Reputation: 45
I am trying to get the SUM of a column SnappersScore from a table LastResult. However, there is nothing in the output at all. Not even an error. Any ideas about what I am doing wrong?
Here it is:
<?php
mysql_connect(xxxxxx);
if (mysql_connect_errno())
{
echo "Failed to connect to MySQL: " . mysql_connect_error();
}
$result = mysql_query('SELECT SUM(SnappersScore) AS TotalGoals FROM LastResult');
$row = mysql_fetch_assoc($result);
$sum = $row['TotalGoals'];
echo $sum;
?>
Upvotes: 0
Views: 216
Reputation: 27618
Only you can debug this, see what the error is:
$result = mysql_query('SELECT SUM(SnappersScore) AS TotalGoals FROM LastResult') or die(mysql_error());
I'll save you the repetitive "dont use mysql_*
, don't use die
in production bla bla bla" - this should point you in the right direction.
This is of course, assuming that when running SELECT SUM(SnappersScore) AS TotalGoals FROM LastResult
in SQL works as expected.
Upvotes: 1