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.
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 …