?> <div class="box row" id="local"> <div class="desc col-xs-3"> <h3>Local Shipping</h3> <p>Details of local shipping.</p> </div> <div class="content col-xs-9"> <ul class="form-set"> <?php $row = 0; foreach($provinces as $provinces){ $row++; $city = $_ajax->get_city($provinces->province_name); ?> <li class="form-group m_b_20" style="position: relative" id="courier-city-<?php echo $row;?>"> <div class="checkbox p_b_15" style="border-bottom: 1px solid #eee"> <label class="control-label"> <input type="checkbox" value="<?php echo $provinces->province_name?>" name="province_name[]" onclick="selectProvince('<?php echo $row;?>')" id="province-checked-<?php echo $row;?>" flag="unchecked" class="cl-province hidden" checked><?php echo $provinces->province_name?> </label> </div> <ul class="clearfix"> <?php $san=0; foreach($city as $city){ $san++; ?>
# ---------------------------------------------------------------------- */ if ($_POST) { require_once '../../../static/_header.php'; class AJAX { private $conn; function __construct() { $this->conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); } function get_city($province) { $sql = "SELECT * FROM tbl_courier_rate WHERE `courier_province` = '{$province}' GROUP BY `courier_city` ORDER BY `courier_city`"; $query = $this->conn->query($sql); $row = array(); while ($result = $query->fetch_object()) { array_push($row, $result); } return $row; } } $_ajax = new AJAX(); $_ajax_province = filter_var($_POST['province'], FILTER_SANITIZE_STRING); $get_city = $_ajax->get_city($_ajax_province); echo '<select class="form-control" id="id-city" name="city">'; foreach ($get_city as $city) { echo '<option value="' . $city->courier_city . '">' . $city->courier_city . '</option>'; } echo '</select>'; }