note 52412 deleted from control-structures.while by nlopess
| From: | nlopess@php.net | Date: | Sat, 30 Apr 2005 00:49:41 +0000 |
| Subject: | note 52412 deleted from control-structures.while by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-88779@lists.php.net to get a copy of this message | ||
Note Submitter: chris at nowhere
----
To "me at julez-edward dot be": while() doesn't "destroy" the query at
all. Each result resource has an internal pointer that references the row being operated on.
mysql_fetch_object increments that pointer, so that the next time, the next row will be returned.
To solve this, use mysql_data_seek. To refine your example:
<?php
$all = @mysql_db_query($db,"SELECT * FROM person");
while ($item = @mysql_fetch_object($all))
{
//do stuff.
}
mysql_data_seek($all, 0); // Returns the internal pointer to the first row of results.
while ($item2 = @mysql_fetch_object($all))
{
echo "Second while succesfully parsed.";
//do other stuff.
}
?>