I am attempting to get a COUNT for a mysql query. Its pretty simple:
SELECT COUNT(id) FROM table WHERE [insert rule here] GROUP BY grouper
The problem is because of that group by at the end, I end up getting a count of rows for each group, when I simply want a total.
Currently to do this I’ll put the results in an array from a query that looks more like this:
$res = mysql_query(SELECT * FROM table WHERE [insert rule here] GROUP BY grouper)
$count = mysql_num_rows($res);
This works ok, but I’d just like to use COUNT.
How is this accomplished?
Add
WITH ROLLUPafter your group by statement:SELECT COUNT(id) FROM table WHERE [insert rule here] GROUP BY id WITH ROLLUP