Forum Moderators: coopster

Message Too Old, No Replies

MySql - Total Of Values In A Single Column

MySql - Total Of Values In A Single Column

         

angelopc

11:22 am on May 24, 2007 (gmt 0)

10+ Year Member



I'm trying to retrieve the total of all values in a specific column.

I know that I can use some version of "SELECT SUM" to gather the info, but I can't figure out how to convert it to a variable.

Any help?

Here's what I have so far:


<?php
$scoreTotQuery = "SELECT SUM(score)
FROM
pc_complete";
$scoreTotResult = mysql_query($scoreTotQuery);
?>

I want to be able to retrieve the total of all scores that have been recorded, so that I can display the average score.

phparion

11:44 am on May 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<?php
$scoreTotQuery = "SELECT SUM(score) as total_score
FROM
pc_complete";

$sRow = mysql_fetch_array(mysql_query($scoreTotQuery));
$total = $sRow['total_score'];
echo $total, ' is the score';
?>

by the way I will strongly recommend you to study any simple php-mysql tutorial and do not jump to direct solutions.