SQL Query循环通过两个数组?

时间:2015-03-22 00:48:40

标签: php mysql sql loops

我在PHP应用程序中使用下面的SQL Query来查找每个停靠点的匹配ID。

$sql = "SELECT trip_id FROM stop_times WHERE stop_id='5897' AND stop_id='1373'";

我想要做的是让它遍历我的两个数组$toStop$fromStop并找到匹配的trip_id然后输出结果。

$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");

这样的东西?但我不认为这会奏效。

    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]
    }
}

查询后的数据库示例:

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

|

0 个答案:

没有答案