I have a query that is…
SELECT m.msgFrom, m.msgTo, m.msgID, m.subject, m.dateTime, a.username
FROM mailbox m
JOIN accounts a ON (m.msgFrom = a.id)
WHERE msgTo = $user
OR msgFrom = $user
AND parentID = 0
ORDER BY dateTime DESC
LIMIT 250
Is it possible to change this query so that the ON changes depending on the value of msgTo or msgFrom.
I have a user variable. If the user variable equals msgTo get the username where the id equals msgFrom. If the user variable equals msgFrom get the username where the id equals msgTo?
I hope I explained it well enough?
You should be able to use an
IFstatement within theONclause. This will join with the account of the opposite user. (i.e. if the message is from$user, thenusernamewill be for the receiving user and if the message is to$user, thenusernamewill be for the sending user.)