note 104630 deleted from mysqli-result.num-rows by aharvey
| From: | aharvey@php.net | Date: | Wed, 24 Oct 2012 03:37:15 +0000 |
| Subject: | note 104630 deleted from mysqli-result.num-rows by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191512@lists.php.net to get a copy of this message | ||
Note Submitter: randomsort at gmail dot com
----
This may be a bug or a feature, but I do see peculiar behaviour with regards to this feature on php
version 5.2.6-1+lenny10.
The value in mysqli-result->num_rows is not the total number of rows, but rather the number of
rows you have iterated over so far.
<?php
$sql = "valid select statement that yields results";
if($result = mysqli-connection->query($sql, MYSQLI_USE_RESULT))
{
echo $result->num_rows; //zero
while($row = $result->fetch_row())
{
echo $result->num_rows; //incrementing by one each time
}
echo $result->num_rows; // Finally the total count
}
?>
This has had me confused more than a few times,
I hope I can save you some of that trouble.
Regards,
Johan Abildskov