Problem with SUM()

I have a web page that collects numbers and I call them grades in the MySQL database. They insert all fine, but I want to add all those ‘grades’ up to a total number and show it on the page. This is what I have as my SQL:

[php]$sql2 = "SELECT SUM(grade) AS gradeTotal FROM grades[/php]

After I extract everything from the database, it shows nothing at all as the total, when it should be 45.

When I run the command in PHPMyAdmin, it shows “Showing rows 0 - 0 ( 1 total, Query took 0.0004 sec)” but has gradeTotal = 45.

How can I get it to post to the page, so people can view the public grades?

Thanks in advance!

I mean:

[php]$sql2 = “SELECT SUM(grade) AS gradeTotal FROM grades”;[/php]

[php]
$sql2 = “SELECT SUM(grade) AS gradeTotal FROM grades”;
$result = mysql_query($sql2);
$sum = mysql_fetch_assoc($result);
[/php]
now
$sum[‘gradeTotal’] should be a variable of your sum grades

Sponsor our Newsletter | Privacy Policy | Terms of Service