starter starter - 8 months ago 17
PHP Question

how to get "Similar data" from mysql datebase using php?

how to get "Similar data" from mysql datebase using php ?

Table is 'messages'

"PID" it's something like subject..

enter image description here

my php code :

$query = "SELECT A.MID, A.PID, A.notify, max(A.time) as time, B.USERID, B.username, C.PID
FROM messages A, members B, posts C
WHERE ((A.sender='".mysql_real_escape_string($_SESSION['USERID'])."' AND A.reciver=B.USERID AND A.PID=C.PID)
OR (A.reciver='".mysql_real_escape_string($_SESSION['USERID'])."' AND A.sender=B.USERID AND A.PID=C.PID))
GROUP BY B.username
order by A.last_update_time desc";
$m = $results->getrows();

This brings the first one and leave the other , and what I want is to bring everyone , how to do it ?


So as I stated in the comments, your problem is that you are doing GROUP BY B.username and using max() and you are filtering by user id so it will only show one message per user.

The solution was to remove GROUP BY B.username and max(A.time)