I am trying to do an SQL
query to get all the messages sent between 2 users: the "Sender" and the "Reciever" (yes I know this is spelled wrong) are foreign keys to the Users
table.
I want to get back all the messages that the current user sent or received along with the username of the other person involved in the message.
I have the JOIN
working (if I delete the where
clause I get all messages), however I can't figure out how to restrict it using the where
.
mysql_query(sprintf("
SELECT m.Content, us.Name Send, ur.Name Rec, m.Timestamp
FROM Messages m
JOIN Users us ON us.UserID = m.Sender
JOIN Users ur ON ur.UserID = m.Reciever
WHERE Send = '%s' or Rec = '%s'
ORDER BY TIMESTAMP DESC
"), $user, $user);