I’m trying to build a user based message system. I’d like messages to show up that are sent between friends, sort of like a facebook news feed.
I’m using a query:
SELECT friend_user_2, user_id, user_name, sent_id, sent_from_id, sent_to_id
FROM friends, users, sent_messages
WHERE (user_id = sent_from_id AND friend_user_1 = '$user_id' AND sent_from_id = friend_user_2)
OR (friend_user_1='$user_id' AND friend_user_2=sent_to_id AND user_id=sent_to_id) ORDER BY sent_id
The problem im running into, is that the user_id of the sender and receiver aren’t identified separately, it only returns the user_id of the friend. I would think that a table join is necessary to attach the names somehow, or (if this is even possible) nesting another query within the array that’s returned by the query which then queries for each name individually.
Any ideas??
You can get the two user ids using table name or aliases, like: