0

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by edwinhermann
0
$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.

Edited by edwinhermann: n/a

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.