drp935159 2015-04-25 08:57
浏览 46
已采纳

MYSQL订购午夜时间表的PHP列车时刻表

I am trying to order sets of train timetables by their departure times from stations but the problem occurs when a train passes over midnight.

Below is an example of the data flowing into my mysql database. For a given train schedule I have its basic route and basic departure times from each station (Marked by the y under sche). Every now and then I may also receive an update of amended departure times for a given train schedule.

In its self the above is not a problem as I order my data based on the timeref. However my problem comes when a train passes midnight. This is because the times I receive are in pure 24hr format - ie 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

I want to show the data as below (in that order). ie in the order of the original timetable but with an updated time for Luton to 01:10

 London        t256      22:10
 Cricklewood   t256      23:00 
 Luton         t256      01:10
 Leicester     t256      02:00

My below code works fine except where a train crosses midnight

 $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.................
 }

So instead of the above I get the following result, which is wrong

Luton         t256      01:10
Leicester     t256      02:00
London        t256      22:10
Cricklewood   t256      23:00 
  • 写回答

2条回答 默认 最新

  • duanban4769 2015-04-25 09:01
    关注

    If you want to put all times between midnight and 6am after other times, you can do:

    ORDER BY timeref < '06:00', timeref
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程