Jump to content

Get count of different values in the same column

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Bertan

Bertan

    Learning Programmer

  • Members
  • PipPipPip
  • 43 posts
I been trying to put these two queries into one, anyone know how this can be accomplished?


$query = "SELECT COUNT(rate) AS Likes 

		  FROM ratings				

		  WHERE image_id = '{$image_id}' AND rate = 1";

$result = mysql_query($query);

$rate1 = mysql_fetch_assoc($result);


$query = "SELECT COUNT(rate) AS Dislikes 

		  FROM ratings				

		  WHERE image_id = '{$image_id}' AND rate = -1";

$result = mysql_query($query);

$rate2 = mysql_fetch_assoc($result);


echo $rate1['Likes'], $rate2['Dislikes'];


Thanks for any help

Yours,
Bertan

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
SELECT COUNT(rate) AS Likes , rate FROM ratings group by rate WHERE image_id = '{$image_id}'
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users