} function get_city($post_province) { $sql = "SELECT * FROM cities WHERE `province` = '{$post_province}' ORDER BY `city_name`"; $query = $this->conn->query($sql); $row = array(); while ($result = $query->fetch_object()) { array_push($row, $result); } return $row; } } $_ajax = new AJAX_CLASS(); if ($_POST['province'] != '') { $ajx_province = filter_var($_POST['province'], FILTER_SANITIZE_STRING); $city = $_ajax->get_city($ajx_province); /* --- DATA --- */ echo '<select class="form-control" id="id-city-billing" name="checkout_billing_city">'; echo '<option value="">-- City --</option>'; foreach ($city as $city) { echo '<option value="' . $city->city_name . '"'; if ($_global_user->user_city != '') { if ($city->city_name == $_global_user->user_city) { echo 'selected="selected"'; } } else { /* if($city->city_name == 'Jakarta'){ echo 'selected="selected"'; } */
} function get_city($post_courier_province) { $sql = "SELECT * FROM tbl_courier_rate WHERE `courier_province` = '{$post_courier_province}' GROUP BY `courier_city` ORDER BY courier_city ASC"; $query = $this->conn->query($sql); $row = array(); while ($result = $query->fetch_object()) { array_push($row, $result); } return $row; } } $_ajax = new AJAX_CLASS(); $ajax_city = filter_var($_POST['province'], FILTER_SANITIZE_STRING); $ajax_country = filter_var($_POST['temp'], FILTER_SANITIZE_STRING); $city = $_ajax->get_city($ajax_city); if ($_global_user->user_city == '') { $_global_user->user_city = ''; } else { $_global_user->user_city = $_global_user->user_city; } if ($ajax_country == 'Indonesia') { echo '<select class="form-control" id="id-city" name="city">'; foreach ($city as $city) { echo '<option value="' . $city->courier_city . '" '; if ($_global_user->user_city != '' && $_global_user->user_city == $city->courier_city) { echo 'selected="selected"'; } echo '>' . $city->courier_city . '</option>'; } echo "</select>";