multiple mysql_fetch_array() calls

This is a discussion on multiple mysql_fetch_array() calls within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi All, I've got a simple query hopefully somebody can clear up for me. I need to make a ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-26-2005
Dave Moore
 
Posts: n/a
Default multiple mysql_fetch_array() calls

Hi All,
I've got a simple query hopefully somebody can clear up for me. I need to
make a query on a database to select a set of table rows, using something
like:

$result = mysql_query($query);

I can then use mysql_fetch_array in a while loop to access each row in the
result. This all works fine.

However, what I'd like to do is to go through this result more than once.
ie. use mysql_fetch_array() to go through each row in $result more than
once. How do I do this?. There appears to be no my of resetting
mysql_fetch_array back to the beginning of the $result once all rows have
been erad once.

I don't want to make multiple identical queries on the database, simply to
read the same information.

Any ideas?.

Ta,
Dave


Reply With Quote
  #2 (permalink)  
Old 05-26-2005
Paul
 
Posts: n/a
Default Re: multiple mysql_fetch_array() calls

Dave Moore wrote:
> Hi All,
> I've got a simple query hopefully somebody can clear up for me. I need to
> make a query on a database to select a set of table rows, using something
> like:
>
> $result = mysql_query($query);
>
> I can then use mysql_fetch_array in a while loop to access each row in the
> result. This all works fine.
>
> However, what I'd like to do is to go through this result more than once.
> ie. use mysql_fetch_array() to go through each row in $result more than
> once. How do I do this?. There appears to be no my of resetting
> mysql_fetch_array back to the beginning of the $result once all rows have
> been erad once.
>
> I don't want to make multiple identical queries on the database, simply to
> read the same information.
>
> Any ideas?.
>
> Ta,
> Dave
>
>

Store your first time result in your own query.. and then just loop your
own query as many times as needed...

$yourArray = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC) {
$yourArray[] = $row;
}

then just do this as many times as needed...

foreach($yourArray as $rowNum => $row) {
//$row would be same as the original $row inside the while loop
inside this loop.
}
Reply With Quote
  #3 (permalink)  
Old 05-27-2005
Steve
 
Posts: n/a
Default Re: multiple mysql_fetch_array() calls

You can also use this:

mysql_data_seek ($result, 0);


http://us4.php.net/manual/en/functio...-data-seek.php

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:19 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0