| Mark Benson 2004-11-24, 8:55 am |
| 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 o
r somehow not resetting $result. Very odd...
--
Mark Benson
http://homepage.mac.com/markbenson
|