ds3422222 2015-03-22 00:48
浏览 34

SQL Query循环通过两个数组?

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

|

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大