我正在尝试为私人消息创建一个用户收件箱,其中它显示两个人之间的一个最近的消息,并且最近的订单也是最近的订单。它应该像Facebook消息收件箱一样执行,您可以在其中单击最新消息的预览以查看完整对话,并且最近也会按顺序排列对话。这是我到目前为止的陈述,但它没有显示任何内容,我无法弄清楚如何解决它。有人有什么建议吗?
$sqlInbox = "
SELECT sender, receiver, message, parent, rView
FROM (SELECT sender, receiver, message, parent, rView
FROM messages
WHERE receiver='$log_username' OR sender='$log_username'
ORDER BY timestamp DESC)
GROUP BY parent
ORDER BY timestamp DESC";
父列表示完整的对话,因此无论发送或接收的是谁,两个设置的人之间的任何消息都将在表中具有相同的父ID。提前谢谢。
答案 0 :(得分:0)
我注意到的一件事是你需要按照你选择的所有列进行分组。
SELECT sender, receiver, message, parent, rView
FROM (SELECT sender, receiver, message, parent, rView
FROM messages
WHERE receiver='$log_username' OR sender='$log_username'
ORDER BY timestamp DESC)
GROUP BY sender, receiver, message, parent, rView
ORDER BY timestamp DESC
答案 1 :(得分:0)
检查这是否有效..
SELECT sender, receiver, message, parent, rView
FROM messages
WHERE receiver='$log_username' OR sender='$log_username'
ORDER BY parent ASC, timestamp DESC
答案 2 :(得分:0)
$sqlInbox = "
SELECT a.*
FROM (SELECT * FROM messages
ORDER BY timestamp DESC) AS a
WHERE receiver='$log_username' OR sender='$log_username'
GROUP BY parent
ORDER BY timestamp DESC";