If I have a table which looked something like
(`id`, `category`, `content`, `post_time`)
And I wanted to count the categories WHERE (for example) post_time > ‘1326600000’
I want the data to be displayed something like this:
categorys['cat_1'] = 4
categorys['cat_2'] = 2
categorys['cat_3'] = 1
The only way I can think of doing this is getting every row in MySQL.
Create a list of categories.
Then do a count(id) as cat_count WHERE category = ‘category_from_list’
Is there a better way?
Yes:
(MySQL actually makes the GROUP BY clause optional — if you select both
categoryandCOUNT(1), it will infer the GROUP BY clause — but you should include it anyway.)