faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 14 people (43%) answered Yes
Recently 4 of 10 people (40%) answered Yes


Doing a query with COUNT * , then showing only distinct values of the query with the count value attached, like "Yellow (23)", dropdown menu.
need script that counts entries with specific criteria then using output to decide to echo text

Aug 6th, 2000 19:24
Jason Wong, Max Palmar, Evan Heller, Onnig Sayadian,

A better way to do this is such:
$result = mysql_query("select blah from bleh where X") or die 
(mysql_error(); <br>
$count = mysql_num_rows($result);<br>
if ($row = mysql_fetch_array($result))<br>
print $row["blah"] . "(" . $count . ")"; <br>
} while if ($row = mysql_fetch_array($result))<br>
or you can do this just to get the count included
select count (*) as the_count, blah from bleh where X
ignore the <br> tags..sorry
Thanks for your answer.  
When I do this the $count variable just counts the total number of rows 
in the array and prints that with each result as it loop through like 
         Yellow (53)
         Green (53)
         Red (53)
meaning it dosnīt count the number of yellows in a column, and greens, 
and reds, etc. etc.
Like : 
          Yellow (12)
          Green (8)     
          Red (33)
I want to show a list of distinct values in a column with the number of 
instances of it in the column. Any ideas? 
You need to do something like this:
SELECT ColourColumn, COUNT(ColourColumn) FROM YourTable GROUP BY