0

我正在尝试为私人消息创建一个用户收件箱,其中显示两个人之间最近的一条消息,以及最近的所有对话的顺序。它应该像 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。提前致谢。

4

3 回答 3

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";
于 2013-10-25T14:48:47.667 回答
0

检查这是否有效..

SELECT sender, receiver, message, parent, rView
FROM messages 
WHERE receiver='$log_username' OR sender='$log_username'
ORDER BY parent ASC, timestamp DESC
于 2013-10-25T04:12:58.113 回答
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
于 2013-10-25T04:08:35.683 回答