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.

Recommended Answers

All 2 Replies

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...

Thanks... it helped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.