Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: henmar - marraskuu 29, 2006, 01:04:44 AP

Otsikko: Getting query restult out of the loop
Kirjoitti: 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
Otsikko: Re: Getting query restult out of the loop
Kirjoitti: kL - marraskuu 29, 2006, 09:06:57 AP
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>";
Otsikko: Re: Getting query restult out of the loop
Kirjoitti: henmar - marraskuu 29, 2006, 09:38:17 AP
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
Otsikko: Re: Getting query restult out of the loop
Kirjoitti: Rudolf - marraskuu 29, 2006, 09:45:02 AP

$context['member'] = array();
while( $row = mysql_fetch_array($result) {
$context['member'][] = $row;
}


This way you will get an array of rows. ;)
Otsikko: Re: Getting query restult out of the loop
Kirjoitti: henmar - marraskuu 29, 2006, 09:58:35 AP
Thanks Rudolf
It worked perfectly 
henmar