Hi everyone, I need a wee bit of help with the following.

I am calling all country names from a db table and echo-ing out each country name in a list format.

$query = "select * from countries order by Country Desc"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
    echo $row['Country'];
    echo "<br />";
}

this gives me a list of country names from the database, what I would like to do is have the list look like the following.

["country name 1", "country name 2", "country name 3", "country name 4"]

How can I acheive this, thanks

Sounds like you want json_encode()

$countries = array ();
while($row = mysql_fetch_array($result)){
    $countries[] = $row['Country'];
}
echo json_encode($countries);

Oh yes, that is perfect, cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.