Problem using SUM / mysqli::num_rows()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
woodsonoversoul
Forum Newbie
Posts: 1
Joined: Thu Aug 02, 2007 6:36 pm

Problem using SUM / mysqli::num_rows()

Post 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]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

num_rows is not a function, it's an integer.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

var_dump($result->num_rows);
Post Reply