By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,651 Members | 1,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,651 IT Pros & Developers. It's quick & easy.

Reset pointer for mysql_fetch_array($sth)

P: n/a
I'm needing to traverse my $sth twice:

list($date_found, $junk) = mysql_fetch_row($sth);

while (list($date, $stuff1, $stuff2) = mysql_fetch_array($sth)) {
// do stuff
}

But of course, when I do this then the WHILE loop starts at 1 instead
of 0 because mysql_fetch_row leaves the internal pointer at 1. I tried
reset($sth), but this just gives an error that $sth isn't an array.

Is there a way to reset the internal pointer without running a new
query?

TIA,

Jason
Dec 12 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
..oO(Jason Carlton)
>I'm needing to traverse my $sth twice:

list($date_found, $junk) = mysql_fetch_row($sth);

while (list($date, $stuff1, $stuff2) = mysql_fetch_array($sth)) {
// do stuff
}

But of course, when I do this then the WHILE loop starts at 1 instead
of 0 because mysql_fetch_row leaves the internal pointer at 1. I tried
reset($sth), but this just gives an error that $sth isn't an array.

Is there a way to reset the internal pointer without running a new
query?
There's mysql_data_seek(), but why not simply fetch all the data into an
array first and then loop through it as often as you want? That would be
more reliable and portable.

Micha
Dec 13 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.