I am working on a Private Messaging Service (PMS) on my website. This is how my 'message' table on my MySQL database look like.

id sender_id receiver_id message
1 2 3 hi
2 3 2 You good?
3 2 3 sure
4 1 3 hello
5 3 1 yes

Now, i am confused about something. I want that when a user (that is when $_SESSION['id' = 3]) visits the 'message' page, what shows up is the last message from a conversation with the last conversation coming at the top. Something like this:

  1. Yes
  2. sure

Then, when the user clicks on for example, 'Yes', he gets to see all the conversation he had with user with id = 2, i.e.


You good?


Please how do I go about this?

2 Years
Discussion Span
Last Post by diafol

this will do for a simple system.

SELECT ... FROM table WHERE $_SESSION['id'] IN(sender_id, receiver_id) ORDER BY id DESC

However sometimes u want to have several different conversations with same person, so each conversation has its own title etc.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.