<?php |
<?php |
include ("../include/common.inc.php"); |
include ("../include/common.inc.php"); |
$result = Array(); |
$result = Array(); |
if (isset($_REQUEST['term'])) { |
if (isset($_REQUEST['term'])) { |
$term = filter_var($_REQUEST['term'], FILTER_SANITIZE_STRING); |
$term = filter_var($_REQUEST['term'], FILTER_SANITIZE_STRING); |
$query = "Select stop_name,min(stop_lat) as stop_lat,min(stop_lon) as stop_lon from stops where stop_name LIKE :term group by stop_name"; |
$query = "Select stop_name,min(stop_lat) as stop_lat,min(stop_lon) as stop_lon from stops where stop_name ILIKE :term group by stop_name"; |
$query = $conn->prepare($query); |
$query = $conn->prepare($query); |
$term = "$term%"; |
$term = "$term%"; |
$query->bindParam(":term", $term); |
$query->bindParam(":term", $term); |
$query->execute(); |
$query->execute(); |
if (!$query) { |
if (!$query) { |
databaseError($conn->errorInfo()); |
databaseError($conn->errorInfo()); |
return Array(); |
return Array(); |
} |
} |
foreach ($query->fetchAll() as $row) { |
foreach ($query->fetchAll() as $row) { |
$name = $row['stop_name'] . " (" . $row['stop_lat'] . "," . $row['stop_lon'] . ")"; |
$name = $row['stop_name'] . " (" . $row['stop_lat'] . "," . $row['stop_lon'] . ")"; |
$result[] = Array( |
$result[] = Array( |
"id" => $name, |
"id" => $name, |
"label" => $name, |
"label" => $name, |
"value" => $name |
"value" => $name |
); |
); |
} |
} |
} |
} |
echo json_encode($result); |
echo json_encode($result); |
?> |
?> |