so my table looks like
NAME CountryID
AFGHANISTAN AF
ALAND ISLANDS AX
ALBANIA AL
ALGERIA DZ
AMERICAN SAMOA AS
I want the results to look like
$data = array('AFGHANISTAN'=>'AF','AX'=>'ALAND ISLANDS','AL'=>'ALBANIA','DZ'=>'ALGERIA','AS'=>'AMERICAN SAMOA');
in other words, a single array. How do I go about this?
You’ll have to loop through the mysql result set and create that array.
Clearly but what is the best way?
This is what I have now.
$data = array();
while ($row = mysql_fetch_assoc($result)){
$data[] = $row;
}
when I print_r($row) I get get an array that puts each $row in it’s own array which is not what I’m looking for.
Your help is appreciated.
Cups
4
$data = array();
while ($row = mysql_fetch_assoc($result)){
$data[$row['CountryID']] = $row['NAME'];
}
(or maybe you want vice versa?)