querying and Convert to array of Objects

Asked

Viewed 28 times

1

i need to query and Convert Rows of code and Location to a array of Objects in javacript, but im having some issues, could someone help me.

My code here:

$sql = "SELECT code, city_name FROM airports";
$consulta = mysql_query($sql);

while($mostrar = mysql_fetch_assoc($consulta)){
     $locals[] = $mostrar['code'] . " ".$mostrar['city_name'];
}


?>
<script type="text/javascript">
    var allLocations = <?php echo json_encode($locals); ?>;
</script>

What im trying to achive is Something like:

[
    {value:"code", label:"name"},
    {value:"code", label:"name"},
...
];
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.