A4.1 API to Search Places |
|
Write an API named search_places.php that returns an array of (campus, place, cuisine) records in a JSON object. The API accepts an optional query string of name-value pairs as arguments for campus, cuisine, and place. The arguments are used to construct the WHERE clause of CAMPUS_PLACES NATURAL JOIN PLACE_CUISINES. Specifying any of the arguments narrows the search to records equal to the argument or arguments. For example,
Note that the array returned each time contains (campus, cuisine, place) triples. This program can start with the following PHP code: See this video for the first part, then this video for the rest of this PHP version. <?php $user = '*****'; // username you use to log into cPanel $campus = ''; $cuisine = ''; $place = ''; $dsn = "mysql:host=$host;dbname=$database"; $sql = "SELECT CAMPUS, PLACE, CUISINE FROM CAMPUS_PLACES NATURAL JOIN PLACE_CUISINES"; /* add your code to add WHERE clause to SQL statement */ $places = Array(); while ($row = $statement->fetch()) array_push($places,$row); $out= json_encode([ |