How to get the value out of loop
example:
while( $row = mysql_fetch_array($result) {
$context['member'] = $row;
}
echo "<pre>", print_r($context['member']) , "</pre>";
but when i write the above code i get only the last row.How can i get the full array outside of the loop.
thanks
Lainaus käyttäjältä: henmar - marraskuu 29, 2006, 01:04:44 AP
How to get the value out of loop
example:
while( $row = mysql_fetch_array($result) {
$context['member'] = $row;
}
echo "<pre>", print_r($context['member']) , "</pre>";
but when i write the above code i get only the last row.How can i get the full array outside of the loop.
thanks
what thats doing is going through all the rows first and then echoing something. if you want it to each something each time, put the } after the echo "<pre>", print_r($context['member']) , "</pre>";
Thanks k_talk for the reply
Ya i know if i put echo "<pre>", print_r($context['member']) , "</pre>"; before } , it will display whole array.But what i exactly want is to store the values from $row into an array and use that array outside the while( $row = mysql_fetch_array($result) loop.Thats why i was trying to get the print_r() value outside the loop, but when i print the array outside the loop it only displays the last row.
Thanks
Henmar
$context['member'] = array();
while( $row = mysql_fetch_array($result) {
$context['member'][] = $row;
}
This way you will get an array of rows. ;)
Thanks Rudolf
It worked perfectly
henmar