1.11M Members

echo row in php

 
0
 

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

 
0
 

Sounds like you want json_encode()

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

Oh yes, that is perfect, cheers

Question Answered as of 2 Years Ago by pritaeas
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: