I’m writing a PM (private messages) system in PHP for one of my projects, and I’m stuck with a single MySQL query that uses (or should be using) Count. The query would take place in a function, which is supposed to return the value of unread messages for $id user.
My table layout looks like this:
___________________________________________________________________________________
+-message_id--||--from_user--||--to_user--||--content--||--date_sent--||--is_read-+
And I wrote a query like that:
$count = mysql_query("
SELECT Count(from_user)
FROM messages
WHERE to_user='$id'
AND is_read=0
GROUP BY to_user
",$connection);
I’m not really familiar with this Count/Group By stuff, so I’m not sure about what I did wrong. I did a few Google searches, but didn’t find anything which could be useful for me.
If you could help me about this little problem, that would be awesome.
Thanks! 🙂
Remove the
GROUP BYclause: