Using a loop on a result destroys array??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux