I need to query and convert rows of code and location to 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"},
...
];