Jump to content

[SOLVED] Problem using SUM


woodsonoversoul

Recommended Posts

Can anyone please explain why this doesn't return the sum of the values stored in "price"...

 

// Compute total spent
  $sql = "SELECT SUM(price) AS total FROM purchase";
  if ($result = $mysqli->query($sql)) {
    if ($mysqli->num_rows()) {
      $row = $result->fetch_assoc();
      echo $row['total'];
    }
  } else {
    echo $mysqli->error;

Link to comment
https://forums.phpfreaks.com/topic/63112-solved-problem-using-sum/
Share on other sites

try
// Compute total spent
  $sql = "SELECT SUM(price) AS total FROM purchase";
  if ($result = $mysqli->query($sql)) {
    if ($result->num_rows) {
      $row = $result->fetch_assoc();
      echo $row['total'];
    }
  } else {
    echo $mysqli->error;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.