Mysql Group by column names
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
开发者_Go百科
The result I get:
array(0 => 10, 1 => 3);
I want a result like this:
array('likes' => 10, 'dislikes' => 3);
Add v.kind
to your field list:
SELECT v.kind, COUNT(v) as likes FROM Vote v GROUP BY v.kind
I think you use
mysql_fetch_array
to get your results, you have to use
mysql_fetch_assoc
I hope to help you.
You can return an associative array using mysql_fetch_assoc.
精彩评论