hi

I would like to be able produce statistics on my web page by counting the numbers of rows in my sql database.

for example.

within my database i have 10 defects in my table called "defects". 9 defects are major, 1 defect is a minor.

is there a way to extract this data in numeric form rather than printing the values as they come?

i would like statistics in my web page to tell me how many defects are major and how many are minor.

major defects: 9
minor defects: 1

something like: echo count FROM defects WHERE name=major eventually i would like to be able to produce graphs but i think that is a bit beyond me but simple tables showing the statistics would be very useful for a start.

thank you for any help you can offer

$sql = "SELECT COUNT(*) FROM tblName WHERE type=\"minor\"";
$result = mysql_query($result);
$row = msql_fetch_row($result);
$number_of_minor_defects = $row[0];

$sql = "SELECT COUNT(*) FROM tblName WHERE type=\"major\"";
$result = mysql_query($result);
$row = msql_fetch_row($result);
$number_of_major_defects = $row[0];

print "Minor defects: ".$number_of_minor_defects."<br>Major defects: ".$number_of_major_defects;

Obviously alter the SQL code to suit your table structure and data. Also I have assumed that you have already initiated your mySQL connection.

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.