I am trying to Sum a number of fields within a SQL Database.
The fields are called week1 to week 13 as they store results for each week.
I have this at the moment however it is not outputting anything, any help would be appreciated. Cheers
<?php
if ($resultsRows == 0){
echo '<p> No results have been listed for you yet. </p>';
}
if ($resultsRows > 0){
$qrytotalresult = "SELECT SUM(week1 + week2 + week3 + week4 + week5 + week6 + week7 + week8 + week9 + week10 + week11 + week12 + week13) FROM results WHERE username = '$username'";
$TotalResult = mysql_query($qrytotalresult);
return $TotalResult;
}
?>
This should do the trick.
(Assumption: There are multiple rows for each user. If each user has only one row than sum function and group by clause can be omitted)