RE: [PHP] reusing MySQL results -- resetting mySQL pointer with mysql_data_seek()
| From: | Daevid Vincent | Date: | Wed, 04 Apr 2001 20:18:19 +0000 |
| Subject: | RE: [PHP] reusing MySQL results -- resetting mySQL pointer with mysql_data_seek() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-47127@lists.php.net to get a copy of this message | ||
Just my two cents here...
I could be mistaken, but wouldn't this method hit the database twice?
I would suggest you take your results the first time and store them in an
array or multidimensional array, then you can get to any element at any time
further down the page.
> -----Original Message-----
> From: Mark Roedel [mailto:MarkRoedel@letu.edu]
> Sent: Wednesday, April 04, 2001 7:52 AM
> To: George Wright; php-general@lists.php.net
> Subject: RE: [PHP] reusing MySQL results
>
>
> > -----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