2

以下のコードには、2 つのテキスト ボックスと 2 つのドロップダウンがあります。これは、コース サブジェクト テーブルからコース コードを選択し、サブジェクト コード ドロップダウンに値を投稿して mysql に更新したときの更新ですが、ドロップダウンからコース コードを選択すると、テーブルが重複しています。アイデアは、サブジェクト コードに値を入力し、mysql に更新することです。

コントローラ:Student_site

    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())
        {
            $data['all_coursesubject_records'] = $query;
        }
        $this->load->view('student_detail_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_records($exam_name)
    {
        $this->db->where('exam_name',$exam_name);
        $query = $this->db->get('student_table');
        return $query->result();
    }

function get_course_code_records($course_name)
    {
        $query = $this->db->get('coursesubject');
        return $query->result();
    }

function get_all_coursesubject_records()
    {
        //echo "exam_name inside get_subject_records".$exam_name;
        $this->db->select('course_code');
        $this->db->select('subject_code');
        $query = $this->db->get('coursesubject');
        return $query->result();
    }   
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();
    }

ビュー:subject_detail_view:

<?php $data = array();
    if(isset($records)){
        foreach ($course_records as $row)
        {
            $data[$row->course_code] = $row->course_code; 
        } 

        $subject_data = array();
        foreach ($all_coursesubject_records as $row)
             {
               $subject_data[$row->subject_code] = $row->subject_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>Register Number</th>
<th>Name </th>
<th>Course Code</th>
<th>Subject Code</th>
</tr></thead>
<?php if(isset($records)) : foreach($records as $row) : ?>
<tr >
<td>
<?php echo anchor('student_site/delete/'.$row->id, 'Delete',array('onClick'=>"return confirm('Are you sure want to delete..?')")); ?>
</td>
<td id="rowUpdate">
<input type=checkbox name="editstudent[]" id="editstudent[]" value="<?php echo $row->id ?>">
</td>
<td ><input class="inputmedium span2" type="text" name="register_number_<?php echo $row->id ?>" id="register_number_<?php echo $row->id ?>" value="<?php echo $row->register_number; ?>" ></td>
<td ><input class="inputmedium span2" type="text" name="name_<?php echo $row->id ?>" id="name_<?php echo $row->id ?>" value="<?php echo $row->name; ?>" ></td>

<td >
<?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);
        echo"hai";
        var_dump ($row->course_code);
?>
<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>

ビュー:subject_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/studentupdate  ',
        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>
4

1 に答える 1

0

フィールド subject_code_id_ を参照していますが、フィールド名と id にはサフィックスがありません。

この行

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

フィールドIDと名前にインデックスを含めるには、このようにする必要があります

<input type="hidden" name="subject_code_id<?php echo $row->id; ?>" id="subject_code_id<?php echo $row->id; ?>" value="subject_code_id<?php echo $row->id; ?>"/>
于 2013-11-19T21:31:25.410 に答える