我正在尝试按照车站出发时间对火车时刻表进行排序,但当火车跨越午夜时会出现问题。下面是流入我的mysql数据库的数据示例。对于给定的火车时刻表,我有其基本路线和每个站点基本的出发时间(用 sche 下的 y 标记)。不时地,我可能还会收到针对某个火车时刻表修正出发时间的更新。就本身而言,这不是问题,因为我可以根据 timeref 对我的数据进行排序。然而,当火车跨过午夜时,我的问题就来了。这是因为我收到的时间格式是纯24小时格式-即01:00。
除了火车跨过午夜的情况外,下面的代码都能正常运行。
所以,与上面的结果不同,我得到了错误的结果。
Count Location Trainid Timeref Sche Update
1 London t256 22:10 y
2 Cricklewood t256 23:00 y
3 Luton t256 01:00 y
4 Leicester t256 02:00 y
5 Doncaster r659 06:00 y
6 Luton t256 01:10 y
7 Sheffield y783 05:00 y
我希望按照原始时间表的顺序展示以下数据,并将卢顿的更新时间更改为01:10。
London t256 22:10
Cricklewood t256 23:00
Luton t256 01:10
Leicester t256 02:00
除了火车跨过午夜的情况外,下面的代码都能正常运行。
$stmt3=$mysql_link->prepare("SELECT count,trainid,location,timeref,sche,update FROM (SELECT count,trainid,location,timeref,sche,update FROM darwinall WHERE trainid=:trainid ORDER BY count DESC) as temp GROUP BY location ORDER BY timeref ASC");
$stmt3->execute(array(':trainid'=>$trainid));
foreach($stmt3->fetchAll(PDO::FETCH_ASSOC) as $row3) {
echo result.................
}
所以,与上面的结果不同,我得到了错误的结果。
Luton t256 01:10
Leicester t256 02:00
London t256 22:10
Cricklewood t256 23:00
count
值有什么意义吗?在我看来,数据库缺少关于站点顺序的重要信息,这将导致意外的错误。 - jeroenCount
只是一个自动递增的 ID 字段。 - Barmar