gpt4 book ai didi

php - SQL按日期和时间排序不起作用

转载 作者:行者123 更新时间:2023-11-29 01:55:27 24 4
gpt4 key购买 nike

我正在尝试按时间和日期对消息进行排序,但它不起作用:这是我的代码:

$sql="SELECT id, message, sender, recipient, date, time, IF(recipient = ".$_SESSION["user"]["id"].", 'received', 'sent') AS direction
FROM message
WHERE
(recipient = $friend_id OR sender = $friend_id)
AND id > $last_message_id ORDER BY time AND date ASC";

最佳答案

您需要像这样将 ASC 放入两列:-

$sql="SELECT id, message, sender, recipient, date, time, IF(recipient = ".$_SESSION["user"]["id"].", 'received', 'sent') AS direction
FROM message
WHERE
(recipient = $friend_id OR sender = $friend_id)
AND id > $last_message_id ORDER BY time ASC, date ASC";

关于php - SQL按日期和时间排序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30380920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com