Forum Moderators: coopster

Message Too Old, No Replies

how to use mysql results a couple times in one script?

         

macdar

9:13 pm on Sep 7, 2004 (gmt 0)

10+ Year Member



Hi,
I've got a problem, I need to use the results from database twice:

Let's say, I'm using a loop:
while($list = mysql_fetch_array($results[result])){
...
}

and then..I need that data one more time:

while($list = mysql_fetch_array($results[result])){
...
}

the problem is the second loop is not visible, I would have to change it to:
while($list2 = mysql_fetch_array($results2[result2])){
...
}
or something like that, but I'm sure there must be a better solution.

thanks.

jatar_k

9:19 pm on Sep 7, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If you need to use them multiple times in the same script then load them into an array and run through the array each time.

but... the reason yours didn't work is because once you run through the result once the internal pointer is at the end. To use it again you need to use mysql_data_seek [php.net] before your second loop to reset the internal pointer to the beginning of the result set.

macdar

9:27 pm on Sep 7, 2004 (gmt 0)

10+ Year Member



thanks, I think now I'm able to resolve that issue!

macdar

9:39 pm on Sep 7, 2004 (gmt 0)

10+ Year Member



yeah, now it works perfect.

many thanks.