开发者

Inbox Functionality with MYSQL

So I am writing a simple inbox private message system.

My table schema is as follows:

  • messageID
  • message
  • sender id
  • receiver id
  • date sent
  • read ( 0 = no , 1 = yes)

I am able to show the messages for the user by relating his userID to 开发者_运维知识库receiverID. However I also want to show the messages he has sent in the inbox to the user.

For example his inbox should show:

Darth Vader - 3 New messages

Luke - 0 new messages (0 because either I read all of them OR i sent him the message and he has not replied).

But what i can only come up with is

Darth Vader - 3 New messages.

Can I get any help with how I can accomplish this SQL call?

EDIT: To Clear the Confusion

I am neither Luke or Darth. I have received 3 New messages from darth, and I have sent a message to luke.

EDIT** Basically I want to be able to make the inbox like how an SMS app would be, where you can see the sms you just sent in a list of sms's by your friends.


SELECT users.username, count(messageID) AS unread
FROM users, messages
WHERE messages.senderID=<USER ID>
AND messages.receiverID=users.userID
AND messages.read=0

Just to make sure I got this right, this query will show all the users I have sent a message to and count the number of those messages which have not been read.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜