Ok, in my PM income list I have this:

$queryIn = "SELECT * FROM users_pm_in WHERE uID = '$USER' ";

Take's all queries and shows them. Now everytime user creates a PM, he creates a "dialog_id" number. If the recipient respond to the user´s PM, the recipient´s PM will also have that number in dialog_id.

So, that's why I would only want to show 1 entry in the income, per dialog_id. How it looks in users_pm_in:

id | uID | bID | msg | dialog_id
 1 | 1 | 2 | Hello | 1
 2 | 2 | 1 | Hi? | 1
 3 | 1 | 2 | Wazzaa? | 1

uID is who is receiving the message, bID is the user who sended it, msg is message, dialog_id shows that they are writing in the same dialog all the same(they responded eachother).

So if I am id 1, in my income list I would have 2 entrys right now, with the query above.

What I want to have, is only 1 IF it's the same dialog (dialog_id and same bID)

And the 1 that it is showing should be the one order by date desc


Not a huge deal, but I find these problems a lot less mentally taxing if I use more descriptive names for database fields. It's a bit more typing, but a year later I can look at the code and still read it.

Written by Surreal Dreams

Accepted Answer

SELECT * FROM users_pm_in WHERE uID = '$USER' GROUP BY dialog_id ORDER BY id DESC
Written by Jochen
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki