note 104630 modified in mysqli-result.num-rows by danbrown
| From: | danbrown@php.net | Date: | Mon, 27 Jun 2011 14:31:26 +0000 |
| Subject: | note 104630 modified in mysqli-result.num-rows by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180991@lists.php.net to get a copy of this message | ||
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
--was--
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. Also bugs.php.net is down.
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
http://php.net/manual/en/mysqli-result.num-rows.php