0

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.

4
  • check your php error_log. Commented Jan 13, 2014 at 14:29
  • what are the { and } there for? Commented Jan 13, 2014 at 14:30
  • Did you check if the query succeeded? $qry = mysql_query(...) or die(mysql_error());. Never assume a query succeeds. They can succeed in exactly ONE way, and fail in a near infinite number of ways. Assume failure, and treat success as a pleasant surprise. Commented Jan 13, 2014 at 14:30
  • you should not be using mysql_* functions in the first place, they have been deprecated for a while. Commented Jan 13, 2014 at 14:37

2 Answers 2

1

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"];
}
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.