note 52411 added to control-structures.while
| From: | chrisatnowhere at osu1 dot php dot net | Date: | Fri, 29 Apr 2005 20:48:51 +0000 |
| Subject: | note 52411 added to control-structures.while | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88769@lists.php.net to get a copy of this message | ||
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.
}
----
Manual Page -- http://www.php.net/manual/en/control-structures.while.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52411
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52411&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52411&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52411&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52411&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52411&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52411&report=yes
Search -- http://master.php.net/manage/user-notes.php