我有一个edu_update.php页面,用户可以在其中更新其学历,我要实现的目标是首先选择教育,然后在第二个下拉列表中列出与之相关的课程,我看不到我在做什么错误,因为数据没有从分支表加载到第二个下拉列表
对于edu_update.php
1.edu_update.php
enter code here
<div class="main-grid3 p-skill">
<div class="col-md-12 form-group2 group-mail">
<?php
//Include the database configuration file
include 'db.php';
//Fetch all the country data
$query = $con->query("SELECT * FROM education ORDER BY id ASC");
//Count total number of rows
$rowCount = $query->num_rows;
?>
<select id="education">
<option value="">Select Highest Qualification</option>
<?php
if($rowCount > 0){
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['id'].'">'.$row['education_name'].'</option>';
}
}else{
echo '<option value="">Education not available</option>';
}
?>
</select>
<script type="text/javascript">
$(document).ready(function(){
$('#education').on('change',function(){
var educationID = $(this).val();
if(educationID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'education_id='+educationID,
success:function(html){
$('#course').html(html);
}
});
}else{
$('#course').html('<option value="">Select Highest Qualification first</option>');
}
});
});
</script>
2.ajaxdata.php
<?php
//Include the database configuration file
include 'dbConfig.php';
if(!empty($_POST["education_id"])){
//Fetch all state data
$query = $con->query("SELECT * FROM branch WHERE education_id = ".$_POST['education_id']." ORDER BY branch_name ASC");
//Count total number of rows
$rowCount = $query->num_rows;
//State option list
if($rowCount > 0){
echo '<option value="">Select Course</option>';
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['id'].'">'.$row['branch_name'].'</option>';
}
}else{
echo '<option value="">Courses not available</option>';
}
else {
echo '<option value="">There is a problem</option>';
}
}
?>