--- a/include/db/stop-dao.inc.php +++ b/include/db/stop-dao.inc.php @@ -46,7 +46,7 @@ } } $query .= " order by stop_name;"; - debug($query,"database"); + debug($query, "database"); $query = $conn->prepare($query); if ($firstLetter != "") $query->bindParam(":firstLetter", $firstLetter); @@ -89,7 +89,7 @@ $query = "Select * from stops where stop_name LIKE :name;"; debug($query, "database"); $query = $conn->prepare($query); - $name = "%" . $name . ";%"; + $name = $name . "%"; $query->bindParam(":name", $name); $query->execute(); if (!$query) { @@ -101,10 +101,10 @@ function getStopsBySuburb($suburb) { global $conn; - $query = "Select * from stops where zone_id LIKE :suburb order by stop_name;"; - debug($query, "database"); - $query = $conn->prepare($query); - $suburb = "%" . $suburb . ";%"; + $query = "Select * from stops where stop_desc LIKE :suburb order by stop_name;"; + debug($query, "database"); + $query = $conn->prepare($query); + $suburb = "%
Suburb: %" . $suburb . "%"; $query->bindParam(":suburb", $suburb); $query->execute(); if (!$query) { @@ -163,19 +163,20 @@ return $query->fetchAll(); } -function getStopTrips($stopID, $service_period = "", $afterTime = "", $limit = "") { +function getStopTrips($stopID, $service_period = "", $afterTime = "", $limit = "", $route_short_name = "") { if ($service_period == "") { $service_period = service_period(); } - $service_ids = service_ids($service_period); - + $service_ids = service_ids($service_period); $sidA = $service_ids[0]; $sidB = $service_ids[1]; + $limitSQL = ""; if ($limit != "") - $limitSQL = " LIMIT :limit "; + $limitSQL .= " LIMIT :limit "; + global $conn; if ($afterTime != "") { - $query = " SELECT stop_times.trip_id,stop_times.arrival_time,stop_times.stop_id,stop_sequence,service_id,trips.route_id,route_short_name,route_long_name, end_times.arrival_time as end_time + $query = " SELECT stop_times.trip_id,stop_times.arrival_time,stop_times.stop_id,stop_sequence,service_id,trips.route_id,trips.direction_id,trips.trip_headsign,route_short_name,route_long_name,end_times.arrival_time as end_time FROM stop_times join trips on trips.trip_id = stop_times.trip_id @@ -183,7 +184,7 @@ WHERE stop_times.arrival_time IS NOT NULL group by trip_id) as end_times WHERE stop_times.stop_id = :stopID AND stop_times.trip_id = end_times.trip_id -AND (service_id=:service_periodA OR service_id=:service_periodB) +AND (service_id=:service_periodA OR service_id=:service_periodB) " . ($route_short_name != "" ? " AND route_short_name = :route_short_name " : "") . " AND end_times.arrival_time > :afterTime ORDER BY end_time $limitSQL"; } else { @@ -193,7 +194,7 @@ stop_times.trip_id join routes on trips.route_id = routes.route_id WHERE stop_times.stop_id = :stopID -AND (service_id=:service_periodA OR service_id=:service_periodB) +AND (service_id=:service_periodA OR service_id=:service_periodB) " . ($route_short_name != "" ? " AND route_short_name = :route_short_name " : "") . " ORDER BY arrival_time $limitSQL"; } debug($query, "database"); @@ -205,6 +206,8 @@ $query->bindParam(":limit", $limit); if ($afterTime != "") $query->bindParam(":afterTime", $afterTime); + if ($route_short_name != "") + $query->bindParam(":route_short_name", $route_short_name); $query->execute(); if (!$query) { databaseError($conn->errorInfo()); @@ -244,4 +247,3 @@ return $timedTrips; } -?>