I am using the below SQL Query in a PHP application to find matching id for each stop.
$sql = "SELECT trip_id FROM stop_times WHERE stop_id='5897' AND stop_id='1373'";
What I would like to do is to have it loop through my two arrays $toStop
and $fromStop
and find trip_id
's that matches then output the results.
$toStop = array("1373","1376","1372","7316","5697","2748","2749","1375","1377","7368","1374","2787","2788");
$fromStop = array("5897","7311","7146","7129","0020","3705","0039","7128","3806","7152","7190","5941","5185","7189","0001","0038","0021","3394","0019","0031","7155","0030");
Something like this? But I don't think this would work.
for ($i = 0; $i < count($array1); ++$i) {
for ($i = 0; $i < count($array2); ++$i) {
SELECT trip_id FROM stop_times WHERE stop_id=$array1[$i] AND stop_id=$array2[$i]
}
}
Sample of Database after query:
SELECT trip_id, stop_id
FROM `stop_times`
WHERE stop_id = '1538'
L66220600132482 1538
0051ML66220630143389 1538
0051ML66220700154239 1538
0051ML66220715159618 1538
0051ML66220730165473 1538
0051ML66220745170994 1538
0051ML66220800176259 1538
0051ML66220815181524 1538
0051ML66220830185989 1538
0070ML577519153855214 1538
0070ML577520154046960 1538
0070ML577521154237374 1538
0072ML577707101039907 1538
0072ML577707351095644 1538
0072ML577708101171393 1538
0072ML577708451246468 1538
0072ML577715402171497 1538
0072ML577716102237827 1538
0072ML577716402305231 1538
0072ML577717102370287 1538
0072ML577717402429337 1538
0074ML575808001813962 1538
0074ML575808051829094 1538
0074ML575808051833737 1538
0074ML575808351938317 1538
0074ML575808351942909 1538
0074ML575809052042897 1538
0074ML575809052043418 1538
0074ML575809152083611 1538
0074ML575809352147477 1538
|