在一个时刻表表中查找下一个时间,其中站是列,行程是行


Finding the next times in a schedule table where stops are columns and trips are rows

我是PHP, mysql等的新手。我在VB和Java中做过一些工作,并且对html相当熟练。

我正试图建立一个PHP网页,从以下形式的时间表查找火车时间:

---------------------------------------------------------
| runId | stop1 | stop2 | stop3 | stop4 | stop5 | stop6 |
---------------------------------------------------------
|   1   |  5:00 |  5:10 |  5:21 | 5:34  | 5:40  | 6:00  |
---------------------------------------------------------
|   2   |  5:30 |  5:40 |  5:51 | 6:04  | 6:10  | 6:30  |
---------------------------------------------------------
|   3   |  6:00 |  6:10 |  6:21 | 6:34  | 6:40  | 7:00  |
---------------------------------------------------------

然后,我想查询知道当前时间和当前时间之后出现的两个条目的停止号(列标题)的表。因此,例如,如果我在stop3,它是5:00,我希望查询返回$time[1]=5:21, $time[2]=5:51,但我不希望返回任何更多的结果(例如,不应该有$time[3] = 6:21集)。

任何帮助将非常感激,这是一个相对较小的项目,如果它使任何不同,你会建议如何设置表。

表应该是这样的:

runId stop time
   1    1  5:00
   1    2  5:10
   1    3  5:21
   ...
   2    1  5:30
   2    2  5:40
   ...
create table schedule (runId int, stop int, `time` time);
insert into schedule (runId, stop, `time`) values
(1,1,'05:00'),
(1,2,'05:10'),
(1,3,'05:21'),
(1,4,'05:34'),
(1,5,'05:40'),
(1,6,'06:00'),
(2,1,'05:30'),
(2,2,'05:40'),
(2,3,'05:51'),
(2,4,'06:04'),
(2,5,'06:10'),
(2,6,'06:30'),
(3,1,'06:00'),
(3,2,'06:10'),
(3,3,'06:21'),
(3,4,'06:34'),
(3,5,'06:40'),
(3,6,'07:00')
;

和查询:

sql = "
    select runId, stop, `time`
    from schedule
    where stop = $stop and `time` > current_time
    limit 2
    ;
";