php - how can i save input value from foreach loop in codeigniter -


$all_student_record_info

has student details student name father name roll no. , section etc. last input field <td><input type="text" name="score[]"></td>

for input each student's score. how can save score each student in mysql. don't have clue how write code save foreach loop.

<?php if (!empty($all_student_record_info)): foreach ($all_student_record_info $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 no data display</strong>       </td> <?php endif; ?> 

any please. mysql table this

score_id | student_id | school_id | class_id | section_id | score 

if understand correctly - problem have group data - otherwise there no possibility assign data properly

imho can try this

<?php  if (!empty($all_student_record_info)):      foreach ($all_student_record_info $v_student_record) :  ?>  <tr>     <td><input type="hidden" name="score[<?=$v_student_record->score_id; ?>][student_id]"  value="<?php echo $v_student_record->student_id ?>"> <?php echo $v_student_record->student_id ; ?></td>     <td><input type="hidden" name="score[<?=$v_student_record->score_id; ?>][school_id]"  value="<?php echo $v_student_record->school_id ?>"> <?php echo $v_student_record->school_name ?></td>     <td><input type="hidden" name="score[<?=$v_student_record->score_id; ?>][class_id]"  value="<?php echo $v_student_record->class_id ?>"> <?php echo $v_student_record->classes_name ?></td>     <td><input type="hidden" name="score[<?=$v_student_record->score_id; ?>][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[<?=$v_student_record->score_id; ?>][score]"></td>                                </tr> <?php     endforeach; else :  ?>       <td colspan="3">       <strong>there no data display</strong>       </td> <?php  endif;  ?> 

now, if @your post array you'll see data grouped score_id (i assumed desired field - because listed first item in mysql example)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -