RE: [PHP-DB] Re: Using A Query Results Multiple Times

From: Date: Fri, 02 Nov 2001 13:34:42 +0000
Subject: RE: [PHP-DB] Re: Using A Query Results Multiple Times
Groups: php.db php.general 
Request: Send a blank email to php-db+get-13935@lists.php.net to get a copy of this message
Easier solution: mysql_data_seek (resource result_identifier, int row_number) Example: $query = "SELECT * FROM mytable"; $result = mysql_query($query) or die("Error: ".mysql_error()); while ($row = mysql_fetch_row($result) ) { ...do some stuff... } mysql_data_seek($result, 0 ); while ($row = mysql_fetch_row($result) ) { ...do some other stuff... } Thus, you don't have to store it in an array. -----Original Message----- From: Chris Lee [mailto:lee@mediawaveonline.com] Sent: Thursday, November 01, 2001 7:20 PM To: php-general@lists.php.net; php-db@lists.php.net Subject: [PHP-DB] Re: Using A Query Results Multiple Times just put it in a loop. while($val = mysql_fetch_result($result)) $array[] = $val; foreach($count = 0; $count < count($array); $count++) echo $array[$count]['product_name']; foreach($count = 0; $count < count($array); $count++) echo $array[$count]['product_name']; php4 has foreach() its better, think of upgrading, there are numerous reasons. -- Chris Lee lee@mediawaveonline.com "Adam Douglas" <adouglas@venmarvent.com> wrote in message news:77FC5DF82857D31196F20090273F71186613D4@orion.venmarvent.com... > I have an instance where I have to query my MySQL database and then > use the multiple row results to create multiple pull down menus on a web > page. My problem is how can I take the results of the query and use them > more the once to create pull down menus? I've always used a while look to > fetch each row of the results and have it create the pull down menu as it > goes through each row. But doing it this way only stores one row of results > in a variable. Is there a way I can grab all the results from a query that > would go into an array so I could use it multiple times? I've lookingere > briefly for a function to MySQL that would allow me to do this but haven't > found anything unless I misunderstand mysql_fetch_array function. At first I > thought I could loop through my while loop and have it put the results from > the query of each row in to a multidimensional array. But then how would I > add to the array after the initial row? > > BTW, I'm using PHP 3.0.16.... so I can't use the added array functions that > PHP 4 has. I do plan on upgrading soon. > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#13935) next »