Rus Rus - 1 year ago 52
Javascript Question

How to query this output in MySQL?

How to query this output in MySQL database? I need the format exactly like this, but I need to retrieve the data from a database instead.

$cities = array(
array('city'=>'New York', state=>'NY'),
array('city'=>'Los Angeles', state=>'CA'),
array('city'=>'Chicago', state=>'IL'),
array('city'=>'Houston', state=>'TX'),
array('city'=>'Phoenix', state=>'AZ'),
array('city'=>'Philadelphia', state=>'PA'),
array('city'=>'San Antonio', state=>'TX'),
array('city'=>'Dallas', state=>'TX'),
array('city'=>'San Diego', state=>'CA'),
array('city'=>'San Jose', state=>'CA'),
array('city'=>'Detroit', state=>'MI'),
array('city'=>'San Francisco', state=>'CA'),
array('city'=>'Jacksonville', state=>'FL'),
array('city'=>'Indianapolis', state=>'IN'),
array('city'=>'Austin', state=>'TX'),
array('city'=>'Columbus', state=>'OH'),
array('city'=>'Fort Worth', state=>'TX'),
array('city'=>'Charlotte', state=>'NC'),
array('city'=>'Memphis', state=>'TN'),
array('city'=>'Baltimore', state=>'MD'),


PHP, this should work

$q = $con->query("SELECT city, state FROM your_table");
$new_array = array();
while ($rows = $q->fetch_object()) {
   $new_array[] = $rows;

I hope this helps...