retrieving array from mysql query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
staxforum
Forum Newbie
Posts: 1
Joined: Fri Dec 27, 2002 11:08 am

retrieving array from mysql query

Post 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
User avatar
Elmseeker
Forum Contributor
Posts: 132
Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA

Post by Elmseeker »

Try using mysql_fetch_array() instead of mysql_fetch_row()...
keymistress
Forum Newbie
Posts: 3
Joined: Wed Dec 25, 2002 10:03 pm
Location: singapore

Post 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)
Post Reply