Reputation: 3143
I've written a query where I select the likes and the dislikes out of a column. I get the results but now I want to add a name to each of the grouped result, is this possible ?
Table structure:
id
,
snippet_id
,
user_id
,
kind
the query:
SELECT COUNT(v) as likes FROM Vote v GROUP BY v.kind
The result I get:
array(0 => 10, 1 => 3);
I want a result like this:
array('likes' => 10, 'dislikes' => 3);
Upvotes: 0
Views: 2758
Reputation: 1785
You can return an associative array using mysql_fetch_assoc.
Upvotes: 0
Reputation: 6660
I think you use
mysql_fetch_array
to get your results, you have to use
mysql_fetch_assoc
I hope to help you.
Upvotes: 0
Reputation: 37364
Add v.kind
to your field list:
SELECT v.kind, COUNT(v) as likes FROM Vote v GROUP BY v.kind
Upvotes: 5