Using a loop on a result destroys array??

From: Date: Wed, 24 Nov 2004 12:31:09 +0000
Subject: Using a loop on a result destroys array??
Groups: php.db 
Request: Send a blank email to php-db+get-37395@lists.php.net to get a copy of this message
I have another issue. I have a fairly large script that requires data to be read for 2 separate purposes from the results of the same query. e.g.: ========================================================= <?php $phish = $_GET["phish"]; $result = mysql_query("SELECT foo, bar, steak FROM footable WHERE foo LIKE '%$phish%'"); // loop *1* where (mysql_fetch_array($result) as $row1) { $crab = $row1["bar"]; } print $crab; ?> <LOTS OF HTML> <?php // loop *2* $array_stuff = array(); $line = 0; where (mysql_fetch_array($result) as $row1) { $array_stuff[$line] = array() $array_stuff[$line]["foo"] = $row1["foo"]; $array_stuff[$line]["bar"] = print $row1["bar"]; $array_stuff[$line]["steak"] = print $row1["steak"]; } print_r $array_stuff; ?> ===================================================== From the above code, loop 2 returns a blank array, the output is simply "Array ()". If I remove the loop (by commentiung it out) that extracts $crab the mysql $result array is suddenly full of the correct values. It seems to me that loop 1 is destroying or somehow not resetting $result. Very odd... -- Mark Benson http://homepage.mac.com/markbenson

« previous php.db (#37395) next »