<?php require("../config/config.php");
$q = $_GET['term'];

$sql = "SELECT distinct state_name as 'state_name',state_code FROM states  where state_name like '" . $db_cust->escape($q) . "%' ORDER BY state_name ASC";
$rows = $db_cust->query($sql);
if($db_cust->affected_rows > 0) {  
  $json_arr = array();
  while ($records = $db_cust->fetch_array($rows)) {
    $json_arr_temp = array();
    $json_arr_temp['name'] = $records['state_name'];
    $json_arr_temp['abbreviation'] = $records['state_code'];
    array_push($json_arr,$json_arr_temp);
  }
    $db_cust->close();
    echo json_encode($json_arr);
} else {
  echo '[]';
}
?>
  