带有PHP/MySQL的消息系统 [英] Messaging System with PHP/MySQL

查看:93
本文介绍了带有PHP/MySQL的消息系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php和mysql创建一个消息传递系统.

Hi I'm trying to make a messaging system with php and mysql.

mysql表很简单: ID 发件人 接收者 文本 时间戳

The mysql table is simple: id sender receiver text timestamp

我正在尝试使消息传递类似于Facebook/Twitter,以便该列表位于对话"中,并查看对话中的最后一条消息.

I'm trying to make the messaging somewhat like Facebook/Twitter so the list is in 'conversations' and the last message in the conversation is viewed.

这是我的atm:

(SELECT * FROM messages WHERE receiver = 13 OR sender = 13 GROUP BY receiver,sender ORDER BY id ASC) ORDER BY id ASC

推荐答案

SELECT messages.* FROM messages, (SELECT MAX(id) as lastid FROM messages 
WHERE receiver = 13 OR sender = 13 
GROUP BY CONCAT(LEAST(receiver,sender),'.',GREATEST(receiver,sender))) as conversations
WHERE id = conversations.lastid
ORDER BY timestamp DESC

您需要的是聊天伙伴之间的唯一对话ID.我已经用子查询模拟了这一点,希望对您有帮助

what you need is a unique conversation id between the chat-partners. i've simulated this with the subquery, hope this helps

这篇关于带有PHP/MySQL的消息系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆