I have two tables, one of utilizadores
where I save username
and id
, and I have another chat
where I save the sender
and reciever
fields, which are the id's from whom you have received and sent a message.
Now, how can I show that the user logged in with id=6
has messages exchanged with id=11
and id=17
.
The user can have 10 messages exchanged with user id=11
and a message only exchanged with id=17
. I just want two lines to appear saying that id=6
has messages exchanged, in this case with two users.
In this way I get all the messages that the user logged in with id=6
has with other users
$sql ="SELECT * FROM chat WHERE reciever = $id
UNION
SELECT * FROM chat WHERE sender = $id";
If the user is id=6
I get 10 messages that this user exchanged with the user id=11
and a message that he exchanged with the user id=17