RE: [PHP] reusing MySQL results
| From: | Mark Roedel | Date: | Wed, 04 Apr 2001 14:52:07 +0000 |
| Subject: | RE: [PHP] reusing MySQL results | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-47059@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: George Wright [mailto:GWright@mhiweb.com]
> Sent: Wednesday, April 04, 2001 9:35 AM
> To: 'php-general@lists.php.net'
> Subject: [PHP] reusing MySQL results
>
>
> Hi All,
>
> I have a page with two forms. Both forms have drop-down option
> lists that are populated by a the same query. The query and
> db connection are all done before either form is introduced
> (this is the select statement, mysql_pconnect(), mysql_select_db(),
> and mysql_query()).
>
> I am using a while loop to build the options. The loop "engine"
> is mysql_fetch_object(), which writes out the values inside of
> option tags.
>
> Everything works fine the first time around, but when I call
> the query result for the second time, it's as if there are no
> rows to return so nothing is written out. No errors are being
> thrown.
Mysql_data_seek() is your friend.
PHP has an internal pointer that it maintains as you move through your
result set. At the end of your mysql_fetch_object while loop, that
pointer is located at the end of the result set.
Mysql_data_seek() is the means for you to "rewind" that pointer to the
any specified row, including the first, of the result set.
See
http://php.net/manual/en/function.mysql-data-seek.php
for more information, including sample code.
---
Mark Roedel (roedelm@letu.edu) || "There cannot be a crisis next week.
Systems Programmer / WebMaster || My schedule is already full."
LeTourneau University || -- Henry Kissinger