user3167217
user3167217

Reputation: 25

Mysql Query sum of a column not displaying

Any idea why this isn't working? When i run it it doesn't display anything.

$qry = mysql_query(" SELECT SUM(payment_received) AS total FROM Orders ");
   {
 $row = mysql_fetch_assoc($qry);
echo $row['total'];
}

Thanks for any help.

Upvotes: 0

Views: 81

Answers (2)

miltos
miltos

Reputation: 1019

Correct your code with the following example

$qry = mysql_query("SELECT SUM(payment_received) AS total FROM Orders");
while ($row = mysql_fetch_assoc($qry)) {
{
    echo $row["total"];
}

Upvotes: 1

aconrad
aconrad

Reputation: 586

$result = mysql_query("SELECT SUM(payment_received) AS total FROM Orders") or die(mysql_error());
$row = mysql_fetch_assoc($result);
print_r($row);

Upvotes: 1

Related Questions