Public holiday consideration in myway timeliness
[busui.git] / lib / autocomplete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
include ("../include/common.inc.php");
$result = Array();
if (isset($_REQUEST['term'])) {
        $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 ILIKE :term group by stop_name";
        $query = $conn->prepare($query);
        $term = "$term%";
        $query->bindParam(":term", $term);
        $query->execute();
        if (!$query) {
                databaseError($conn->errorInfo());
                return Array();
        }
        foreach ($query->fetchAll() as $row) {
                $name = $row['stop_name'] . " (" . $row['stop_lat'] . "," . $row['stop_lon'] . ")";
                $result[] = Array(
                        "id" => $name,
                        "label" => $name,
                        "value" => $name
                );
        }
}
echo json_encode($result);
?>