1
my database table
course subject is my table name
course    subject
-----------------
 bsc1       s1
 bsc1       s2
 bsc2       s3

if i select bsc1 it need to display only subject (s1,s2),if i select bsc2 it need to display only subject (s3) i.e it should corresponding values from MySQL database,please any one help me to rectify this problem. i tried i con't able to rectify.

In controller:

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);
}

In model:

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();

}   

In view:

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);

?>
4

0 回答 0