Page 1 of 1

retrieving array from mysql query

Posted: Fri Dec 27, 2002 11:08 am
by staxforum
Hi all!

Just a simple and (maybe) silly question.

I have a table with 2 fields: abb and pop. I make a query on that table to retrieve those two fields and populate a table. Here is the code:

$result = sql_query("SELECT abb, pop FROM ".$prefix."_test",$dbi);
$i=0;
while(list($abb,$pop)=sql_fetch_row($result,$dbi)){
$tab[$abb]=$pop;

}


Now i want to use $tab outside the while loop ( to generate a graph with Jpgraph)

How can i do that?

I tried to put a "return $tab" just before the closing }, but this didn't help...

thanks for helping :wink

Posted: Fri Dec 27, 2002 8:06 pm
by Elmseeker
Try using mysql_fetch_array() instead of mysql_fetch_row()...

Posted: Fri Dec 27, 2002 10:03 pm
by keymistress
just an additional note:

mysql_fetch_array
- will fetch a result row as an associative array, a numeric array, or both

mysql_fetch_row
- gets a result row as an enumerated array

(above desc from php.net)