未读私信回复的通知计数
我有一个使用 PHP 和 mySQL 并带有通知的私人消息系统。
数据库表具有以下字段(未全部列出) --- message_tbl:
MessageID
senderUserID
RecUserID
Message
Subject
DateTime
Status - whether read or not i.e 0/1
所有回复都存储在第二个表中,因为每条消息都会创建一个线程。父消息中存在一个线程,因此每次加载父消息时,其所有回复也会随之加载。 第二个表看起来有点像这样: -replies_tbl
messageID - FK
senderUserID
rstatus - how should i use this?
Mesage
DateTime
我需要显示所有未读消息的计数。 目前,我运行一个 sql 计数函数来从 message_tbl 中获取未读消息总数,其中状态为 0,用户 ID 等于 RecUserID,这是最简单的部分。
但我有一个小问题是如何获取回复表的计数?数据库设计可以改进吗?
谢谢你们。
I have a Private messaging system using PHP and mySQL with notification.
The database table has following fields(not all listed) --- message_tbl:
MessageID
senderUserID
RecUserID
Message
Subject
DateTime
Status - whether read or not i.e 0/1
All replies are stored in a second table, since each message creates a thread. A thread exist within the parent message, so everytime a parent message is loaded all its replies also are loaded with it.
The second table looks a bit like this: - replies_tbl
messageID - FK
senderUserID
rstatus - how should i use this?
Mesage
DateTime
I need to show count of all the unread messages.
At the moment i run a sql count function to get total unread messages from the message_tbl where status is 0 and userid equal to RecUserID, the easy part.
But i have a small issue is how to get count for the replies table? Can the database design be improved?
thanks guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,回复本身就是一条消息,那么为什么它会进入一个单独的表呢?回复回复会发生什么?看起来你此时的 FK 为空。
我的第一个想法是:
使用该结构,您可以轻松跟踪对回复的回复,并且线程可以继续深入到您想要的深度...
不过只是我的想法...
As I see it, a reply is, itself, a message, so why is it going into a separate table. What happens with a reply to a reply? It would seem you would have a null FK at that point.
My first thought is:
With that structure, you could easily track replies to replies and the thread could continue as deep as you wanted it to ...
Just my thoughts, though ...