Page 1 of 1

Problem using SUM / mysqli::num_rows()

Posted: Thu Aug 02, 2007 6:48 pm
by woodsonoversoul
Can anyone please explain why this doesn't return the sum of the values stored in "price"...

Code: Select all

// 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;
When I use that code I get:

Fatal error: Call to undefined method mysqli::num_rows()

All help is greatly appreciated. Thanks in advance

[/syntax]

Posted: Thu Aug 02, 2007 7:15 pm
by superdezign
num_rows is not a function, it's an integer.

Posted: Thu Aug 02, 2007 7:31 pm
by John Cartwright

Code: Select all

var_dump($result->num_rows);