my database table
course subject is my table name
course subject
-----------------
bsc1 s1
bsc1 s2
bsc2 s3
如果我选择bsc1它只需要显示主题(s1,s2),如果我选择bsc2它只需要显示主题(s3)即它应该是来自MySQL数据库的相应值,请任何人帮我解决这个问题。我试过我无法纠正。
在控制器中:
function studentupdate()
{
$data = array();
$exam_name = $this->input->post('exam_name');
$course_name = $this->input->post('course_name');
if($query = $this->student_model->get_exam_data())
{
$data['exam_data'] = $query;
}
if($query = $this->student_model->get_records($exam_name))
{
$data['records'] = $query;
}
if($query = $this->student_model->get_course_code_records($exam_name))
{
$data['course_records'] = $query;
}
if($query = $this->student_model->get_all_coursesubject_records($course_name))
{
$data['all_coursesubject_records'] = $query;
}
$this->load->view('student_detail_view', $data);
}
模特:
function get_all_coursesubject_records($course_name)
{
$this->db->distinct();
$this->db->select('subject_code');
$this->db->where('course_code',$course_name);
$query = $this->db->get('coursesubject');
return $query->result();
}
在视图中:
function get_subjectdetailsforupdate(index){
alert ("enter first inside");
var course_name = jQuery('#course_code_id'+index).val();
alert("course_name"+course_name);
var exam_name = jQuery('#exam_name_id').val();
alert("course_name"+course_name);
var ssubject_code = jQuery('#subject_code_id'+index).val();
alert("course_name"+course_name);
jQuery.ajax({
data: 'exam_name='+exam_name+'&course_name=' + course_name,
type: 'POST',
url: 'student_site/subjectfilter',
success: function(data){
console.log(data);
jQuery('#subject_code_id'+index).empty().append(data);
}
});
}
<?php
$js = 'class="dropdown_class" id="course_code_id'.$row->id.'" onChange="get_subjectdetailsforupdate()" ';
$js_name = 'course_code_id'.$row->id;
echo form_dropdown($js_name, $data, $row->course_code, $js);
?>
</td>
<td>
<?php
$js = 'class="dropdown_class" id="subject_code_id'.$row->id.'"';
$js_name = 'subject_code_id'.$row->id;
echo form_dropdown($js_name, $subject_data, $row->subject_code, $js);
?>