Forum Moderators: coopster

Message Too Old, No Replies

Populate array with mysql table

I hate arrays

         

mooger35

1:43 am on Jan 19, 2006 (gmt 0)

10+ Year Member



What I would like to do is populate an array with some information pulled from a mysql table.

as an example lets say I have a table that shows:

id ¦ name ¦ nickname

what I would like to do is have my array as follows:

$name_ar = array(
'name1' => 'nickname1',
'name2' => 'nickname2',
'name3' => 'nickname3',
/* and on and on */
);

Arrays are not my favourite things, some help?

mooger35

1:49 am on Jan 19, 2006 (gmt 0)

10+ Year Member



Nevermind... found it

while($row = mysql_fetch_row($result)) {
$myArray[$row[0]] = $row[1];
}
while(list($key,$value) = each($myArray)) {
echo "$key : $value";
}