制作线程私人消息系统

时间:2016-01-24 02:01:56

标签: sql

我正努力在我的网站上制作类似线程的私人消息功能。我是一个新手,但这就是我设置它的方式

两张桌子:

conversations
id, subject, user_one (userid), user_two (userid)
1, test, 13, 14
2, test again, 13, 14

conversation_messages
id, cid, body, date, sender (userid)
1, 1, hello, unixtime, 13
2, 1, hello yourself, unixtime, 14
3, 2, cheese, unixtime, 13

这是显示用户收件箱,其中USERID是当前登录用户的ID。

SELECT c.*, max(cr.date) as date, u.username, cr.sender FROM conversations c
JOIN conversation_replies cr ON cr.cid = c.id
JOIN users u ON u.id = cr.sender
WHERE (c.user_one = '.USERID.' OR c.user_two = '.USERID.')

foreach($inbox as $message) {......................

由于某些原因,即使用户在不同用户之间进行的对话超过1次,它也只会返回带有上述SQL的一行。

我在这里想错了吗?

为什么?

0 个答案:

没有答案
相关问题