Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 创建线程专用消息传递系统_Sql - Fatal编程技术网

Sql 创建线程专用消息传递系统

Sql 创建线程专用消息传递系统,sql,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 your

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

两张表:

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语句

我在这里想错了吗


为什么?

max不会强制结果集仅为一行吗?您可以使用一些示例数据和预期输出创建演示吗。例如,您可以硬编码用户标识。对其他人来说,尝试一些东西会更容易。