PDA

View Full Version : multiple uses of fetch_array()


AsscBB
08-24-2008, 04:06 PM
I'm trying to write some code where I scan through an array multiple times. The symptoms of my code lead me to belive that only the first call to fetch_array() is being used. Are there any limts on how many times you can run fetch_array against the same array?




.
.
.
while($get_result=$db->fetch_array($get_results))
{
//do stuff 1
}

//do stuff 2

while($get_result=$db->fetch_array($get_results))
{
//do stuff 3
}

//do stuff 4

while($get_result=$db->fetch_array($get_results))
{
//do stuff 5
}
.
.
.



My when I activate my plug-in, it looks like "do stuff 3" and "do stuff 5" are being ignored.

If this is a limitation, any suggestions on an alternative?

Thanks!

RLShare
08-24-2008, 04:26 PM
Each time fetch_array is called it moves an internal pointer to the next set of data. The way you have it set up, when the pointer reaches the last set of data the while loop ends. In order to do what you want you would need to use data_seek to move the internal pointer back to the first position after each while loop.

AsscBB
08-24-2008, 06:05 PM
RLShare-

Works like a champ now! Thanks for the info!

Dismounted
08-25-2008, 07:21 AM
You could store all the data into a variable in the first loop, then just loop this variable. I'm guessing it would be slightly faster - but I am not sure.