-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an API method to search business names
Toward #85.
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/autoloader.php'; | ||
|
||
/* | ||
* Use the search string passed in the URL | ||
*/ | ||
if ( isset($_GET['query']) ) | ||
{ | ||
$query = filter_var($_GET['query'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); | ||
} | ||
|
||
$database = new Database; | ||
$db = $database->connect(); | ||
|
||
if (!$db) | ||
{ | ||
header($_SERVER["SERVER_PROTOCOL"]." 500 Internal Server Error", true, 500); | ||
echo json_encode('Error'); | ||
exit; | ||
} | ||
|
||
/* | ||
* Get the first 50 matching records | ||
*/ | ||
$business = new Business; | ||
$business->db = $db; | ||
$business->query = $query; | ||
$results = $business->search(); | ||
|
||
if (!is_array($results)) | ||
{ | ||
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404); | ||
echo json_encode('Error'); | ||
exit; | ||
} | ||
|
||
echo json_encode($results); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters