我已经成功地从国家,州,地区,城镇,城市这样的sql中创建了填充的php。
现在问题是在获得区域下降后我需要城镇和城市之间的OR条件可以任何人帮助。
在区域能够显示所有城镇但需要拆分选择城镇或城市后。AJAX代码
if(isset($_POST["district_id"]) && !empty($_POST["district_id"])){
//Get all town data
$query = $db->query("SELECT * FROM town WHERE district_id = ".$_POST['district_id']." AND status = 1 ORDER BY town_name ASC");
//Count total number of rows
$rowCount = $query->num_rows;
//Display town list
if($rowCount > 0){
echo '<option value="">Select town</option>';
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['town_id'].'">'.$row['town_name'].'</option>';
}
}else{
echo '<option value="">town not available</option>';
}
}
功能声明如下
$('#state').on('change',function(){
var stateID = $(this).val();
if(stateID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'state_id='+stateID,
success:function(html){
$('#district').html(html);
$('#town').html('<option value="">Select district first</option>');
}
});
}else{
$('#district').html('<option value="">Select state first</option>');
$('#town').html('<option value="">Select district first</option>');
}
});
html代码如下
<div id="footer"><select name="district" id="district">
<option value="">Select state first</option>
</select></div>