You are here: Re: multiple mysql_fetch_array() calls « PHP Programming Language « IT news, forums, messages
Re: multiple mysql_fetch_array() calls

Posted by Paul on 05/26/05 23:24

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.
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация