如何从foreach输入字段将数据保存到codeigniter中的mysql

时间:2017-09-05 05:20:03

标签: php mysql codeigniter

如何从foreach输入字段中将数据保存到codeigniter中的mysql。我想在MySQL中保存所有这些值。分数字段应与学生ID字段相关联。我怎样才能做到这一点 ?

<tbody>                 
    <?php if (!empty($all_student_record_info)): foreach ($all_student_record_info as $v_student_record) : ?>
            <tr>
                <td><input type="hidden" name="student_id[]"  value="<?php echo $v_student_record->student_id ?>"> <?php echo $v_student_record->student_id ; ?></td>
                <td><input type="hidden" name="school_id[]"  value="<?php echo $v_student_record->school_id ?>"> <?php echo $v_student_record->school_name ?></td>
                <td><input type="hidden" name="class_id[]"  value="<?php echo $v_student_record->class_id ?>"> <?php echo $v_student_record->classes_name ?></td>
                <td><input type="hidden" name="section_id[]"  value="<?php echo $v_student_record->section_id ?>"> <?php echo $v_student_record->section_name ?></td>                                
                <td><?php echo $v_student_record->student_name ?></td>
                <td><?php echo $v_student_record->student_father_name ?></td>
                <td><?php echo $v_student_record->student_contact_number ?></td>
                <td><?php echo $v_student_record->student_address ?></td>                                
                <td><input type="text" name="score[]"></td>                              
            </tr>
            <?php
        endforeach;
        ?>
    <?php else : ?>
    <td colspan="3">
        <strong>There is no data to display</strong>
    </td>
<?php endif; ?>
</tbody>

1 个答案:

答案 0 :(得分:0)

首先,你应该在控制器上执行此操作

  $data = $this->yourModel->yourfunction()->result(); 

   foreach($data as $data){ 
   $array = array(
        'yourtablecolumn' => $data->student_id,
        'youttablecolumn => $data->student_id,
    ),
    $insert = $this->db->insert('yourtable',$array);
   if($insert){
       echo 'Succes';
   }else{
      echo 'No';
   }

}