0

Hello,
im in a jam, i have tried to use count for my database to count a row, but i was wondering how to count individual things by name.
ex..
+++++++++++++++
+ id + name + color +
+++++++++++++++
+ 1 + joe + blue +
+ 2 + frank + red +
+ 3 + mike + black +
+ 4 + jack + black +
+++++++++++++++

no all i want to do is display a count for each color along instead of displaying 1 blue, 1 red, and 2 black. all i want to do is display black only.. so 2 black, and not the rest of the data? ive seen things, but dont help, like..

<?php
$query = ("SELECT name, count(color) FROM table");
$result = mysql_query($result)// blah blah blah
echo " ".$row['count(color)']."";
?>
i just want to display a single thing not all of them and how man. sorry if im confusing.
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by fobos
0

Hello,
im in a jam, i have tried to use count for my database to count a row, but i was wondering how to count individual things by name.
ex..
+++++++++++++++
+ id + name + color +
+++++++++++++++
+ 1 + joe + blue +
+ 2 + frank + red +
+ 3 + mike + black +
+ 4 + jack + black +
+++++++++++++++

no all i want to do is display a count for each color along instead of displaying 1 blue, 1 red, and 2 black. all i want to do is display black only.. so 2 black, and not the rest of the data? ive seen things, but dont help, like..

<?php
$query = ("SELECT name, count(color) FROM table");
$result = mysql_query($result)// blah blah blah
echo " ".$row['count(color)']."";
?>
i just want to display a single thing not all of them and how man. sorry if im confusing.

Try this

$sql  =  " SELECT COUNT(color) FROM `table` WHERE `color` = 'black'";
	  
	  $result = mysql_query($sql);
	  
	  if (isset($result)){
		  
		while ($row = mysql_fetch_array($result)){
			 
			 echo "There are " .$row['COUNT(color)'];
		
		}
		 }
			else{
				echo "there was an error " . mysql_error();
			}

Hope it helps...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.