2017-09-05 51 views
0

如何將數據保存到codeigniter中的mysql從foreach輸入字段中。我想將所有這些值保存在MySQL中。分數字段應與學生ID字段相關聯。我怎樣才能做到這一點 ?如何從foreach輸入字段將數據保存到codeigniter中的mysql

<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> 
+0

所以,你要的是,插入所有DataArray中的對象'$ all_student_record_info'到你的MySQL數據庫是什麼? – Gagantous

+0

你想在你的控制器或視圖中添加數據嗎? – Gagantous

+0

是在控制器中,並保存到mysql – LEARNER

回答

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

} 
相關問題