drag
February 2, 2010, 8:53pm
1
Hi,
I have queried database and got 2 values ($city, $country) that I need.
Now, I want to make an array like that:
$items = array(
"London"=>"Great Britain",
"Liverpool"=>"Great Britain",
"Madrid"=>"Spain",
"Barcelona"=>"Spain",
...);
My code:
...
$sql="select country, city from $table group by city";
$items = array();
while($row=mysql_fetch_array($result)) {
array_push($items, $city, $country);
}
How to do that?
Thanks.
while($row=mysql_fetch_array($result)) {
$items[ $row['city'] ] = $row['country'];
}
Be aware, that this format won’t accommodate multiple countries having a city name in common. Well, neither will the sql query.
system
February 2, 2010, 9:00pm
3
I have queried database and got 2 values ($city, $country) that I need.
You didn’t get it actually.
the only variable you have is $row
while($row=mysql_fetch_array($result)) {
$items[$row["city"]] = $row["country"];
}