use mysql_data_seek() just like you'd use reset() on an array.

from php.net :

"mysql_data_seek() moves the internal row pointer of the MySQL result
associated with the specified result identifier to point to the specified
row number. The next call to mysql_fetch_row() would return that row. "


-----Original Message-----
From: George Wright [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 04, 2001 10:35 AM
To: '[EMAIL PROTECTED]'
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.

I know the resultant query object still exists, because I can 
access some of its properties (e.g.: mysql_num_rows has 
a value when it is called at this same place in the code as the 
second loop set).

One caveat: This code DOES work if, just before the second call 
to build the second set of options, I resend the query (again using 
mysql_query()).

I would think that looping on the object the first time should only 
read from it and not otherwise change it.  Why am I unable to reuse 
this object in a second mysql_fetch_object() without resending 
the query?

I have tried distinguishing the variable names that I set the results to for

each loop and this doesn't seem to make a difference.

Running PHP 4.0.4, MySQL 3.23.22-beta on Win2K.

Thanks, George

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to