Forum Moderators: coopster
I am querying a db using the RAND() function and need to have access to the result set in two ways. The first for the full while loop to function properly, but I also need to have a nested loop that goes through the result set entirely, before continuing the next iteration of the first while loop.
Some pseudo code to illustrate.
while($row = mysql_fetch_array($sql)){
do some stuff
Nested while loop (accessing same result set){
some more stuff
}//end of nested while loop
do more stuff
}//end of primary while loop...now back to beginning for next iteration
Basically, run query, begin 1 iteration of while loop accessing result set, then loop through entire result set before starting next iteration of the first while loop and so on.
Exactly how would I accomplish the above without screwing up the db pointer on the primary iteration?
I hope the above make sense...think I confused myself
$outercnt = 0;
while($row = mysql_fetch_array($sql)){
// do some stuff
mysql_data_seek($sql,0);
while ($internalrow = mysql_fetch_array($sql)){
// some more stuff
}
mysql_data_seek($sql,$outercnt);
// do more stuff
$outercnt++;
}
mysql_data_seek() [ca.php.net] is your friend :)