1

在下面有 2 个下拉课程代码和主题代码。在我的更新部分中,当我选择课程代码时,它应该从课程主题表中填充相应的主题代码并更新到 mysql。我的问题是我得到了相关的下拉主题代码,但它没有将值更新为 mysql。注:课程代码和科目代码来自课程科目表。课程代码正在更新,但主题代码未更新。

控制器:student_model

function subject_list()
    {   
        $data = array();
        $exam_name = $this->input->post('exam_name');
        $course_name = $this->input->post('course_name');
        if($query = $this->student_model->get_subject_records($exam_name,$course_name))
        {
            $data['all_coursesubject_records'] = $query;
        }
        $this->load->view('code_view', $data);
    }

function manage_student()
    {
        $data['title']="Manage Student";
            //query model to get data results for form
            $data=array();
            if($query=$this->student_model->get_student_records()){
            $data['records']=$query;
            }
            $editstudent = $this->input->post('editstudent');
            if( $this->input->post('editstudent') != false ){
            foreach($editstudent as $row_id)
              {
                $this->form_validation->set_rules("register_number_" . $row_id, "register_number", "required|min_length[2]");
              }
            }
            if ($this->form_validation->run() == FALSE){
            $data["message"]="";

                //$this->load->view("master_data/view_master_data_header",$data);
                //$this->load->view("master_data/view_master_data_nav");
                $this->load->view("student_detail_view",$data);
                //$this->load->view("master_data/view_master_data_footer");

            } else {
                // single update - working
                if( $this->input->post('editstudent') != false )
                {
                    foreach ($editstudent as $row_id)
                    {
                        $data = array( 
                        'register_number' => $this->input->post('register_number_'.$row_id),
                        'name' => $this->input->post('name_'.$row_id),
                        'course_code' => $this->input->post('course_code_id'.$row_id),
                        'subject_code' => $this->input->post('subject_code_id'.$row_id),

                        );

                        $this->student_model->update_student_records( $row_id, $data );
                        redirect('student_site','refresh');
                    }
                    $this->session->set_flashdata('dbaction', 'Selected Records have been updated successfully');


                    }

            }
    }

模型:student_model

function get_subject_records($exam_name,$course_name)
    {
        //echo "exam_name inside get_subject_records".$exam_name;
        //$this->db->select('course_code,subject_code');
        //$this->db->where('exam_name',$exam_name);
        $this->db->where('course_code',$course_name);
        $query = $this->db->get('coursesubject');
        return $query->result();
    }

function get_subject_code_records()
    {
        $this->db->distinct();
        $this->db->select('subject_code');

        $query = $this->db->get('coursesubject');
        return $query->result();

    }
function update_student_records($row_id, $data)
    {
        $this->db->where('id',$row_id);
        $this->db->update('student_table',$data);  
    }

视图:subject_detail_view

<?php 
    $attributes=array(
        'name'=>'updatecustomer',
        'id'=>'updatecustomer'
        );
    echo form_open('student_site/manage_student',$attributes);
?>
<div id="validation_failed">
    <?php
        echo validation_errors();
    ?>
    <?php $data = array();
    if(isset($course_records)){
        foreach ($course_records as $row)
        {
            $data[$row->course_code] = $row->course_code; 
        } }

    ?>
     <div id="Processy ">
<table class="display table table-bordered table-striped" id='studenttable'>
<thead>
<tr font style='font-size:13px'>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>Course Code</th>
<th>Subject Code</th>
</tr></thead>
<?php if(isset($records)) : foreach($records as $row) : ?>
<tr >

<td >
<input type=checkbox name="editstudent[]" id="editstudent[]" value="<?php echo $row->id ?>">
</td>
<td >
//drop down course code
<?php 

        $js = 'class="dropdown_class" id="course_code_id'.$row->id.'" onChange=" get_subjectdetails112('.$row->id.')" '; 
        $js_name = 'course_code_id'.$row->id;
        echo form_dropdown($js_name, $data, $row->course_code, $js);

?>
<input type="hidden" name="index" id="index" value="<?php echo  $row->id; ?>"/>
</td>
<td>    
    <div id="subject_code_id<?php echo $row->id; ?>" ></div>
   <input type="hidden" name="subject_code_id" id="subject_code_id" value="subject_code_id<?php echo $row->id; ?>"/>
</td></tr>


<?php endforeach; ?>
</table>
</div>
<input type="hidden" name="exam_name" id="exam_name" value="<?php echo $row->exam_name; ?>" />
<?php else : ?>

<?php endif; ?>

视图:student_update

<script type="text/javascript" charset="utf-8">



 function get_subjectdetails112(index) {
 alert ("enter firstMAIN");
    //var index = jQuery('#index').val();
    //alert("index"+index);
    var course_name = jQuery('#course_code_id'+index).val();
    alert("course_name"+course_name);
    //var exam_name = jQuery('#course_name_id>option:selected').text();
    var exam_name = jQuery('#exam_name_id').val();
    var subject_code = jQuery('#subject_code_id'+index).val();
    alert(subject_code);
    //var partsArray = exam_name.split('.');
    //alert("ssubject_code"+ssubject_code);
    //alert("course_name"+course_name);
    //alert("exam_name"+exam_name);
    jQuery.ajax({
        data: 'exam_name='+exam_name+'&course_name=' + course_name,
        type: 'POST',
        url: 'student_site/subject_list  ',
        success: function(data){
        //alert("inside change");
            console.log(data);
            //alert ("data"+data);
            //for(var j = course_name; j < ssubject_code; j++)
        //{
            jQuery('#subject_code_id'+index).empty().append(data);
        //}
        }

    });
} 
</script>

视图:code_view

<?php
if(isset($all_coursesubject_records)){
        $subject_data = array();
        foreach ($all_coursesubject_records as $row)
             {
               $subject_data[$row->subject_code] = $row->subject_code; 
              }  
       }

        echo form_dropdown('subject_code_id', $subject_data,'class="dropdown_class"  id="subject_code_id"');
        ?>
4

1 回答 1

0

在您的 student_model(控制器)文件中,尝试在此处删除逗号: 'subject_code' => $this->input->post('subject_code_id'.$row_id),

改成:

$data = array('register_number' => $this->input->post('register_number_'.$row_id),
          'name' => $this->input->post('name_'.$row_id),
          'course_code' => $this->input->post('course_code_id'.$row_id),
          'subject_code' => $this->input->post('subject_code_id'.$row_id));

不确定这是否会产生影响。

于 2013-10-09T02:24:43.530 回答