0

I've an empty MySQL pets table. When I use the following PHP code, it provides one(1).

$query = "SELECT COUNT(*) FROM pets";
$result = mysqli_query($connect,$query);
$total=mysqli_num_rows($result);
echo $total;
Reza Ansar
  • 119
  • 5
  • are you sure the table's empty? an empty table would have 0 rows. e.g. if you do `select count(*) from pets`, you'd get one row of results, and the count SHOULD be `0` if the table was truly empty. – Marc B Aug 26 '14 at 22:03
  • Use [PDO](http://php.net/manual/en/book.pdo.php) instead. – Be0wulf Aug 26 '14 at 22:04

1 Answers1

0

You get the count of the results as a result, there is no num_rows actually you are getting the properities of the result like that...

object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> NULL ["num_rows"]=> int(1) ["type"]=> int(0) }
Ozan Kurt
  • 3,731
  • 4
  • 18
  • 32