$all_student_record_info
有学生姓名父亲姓名的学生详细信息。最后输入字段<td><input type="text" name="score[]"></td>
输入每个学生的分数。如何为MySQL中的每个学生保存分数。我真的没有任何线索如何编写代码来保存foreach循环。
<?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; ?>
请帮助。 MySQL表就像这样
score_id | student_id | school_id | class_id | section_id | score
答案 0 :(得分:-1)
如果我理解正确 - 您必须将数据分组的问题 - 否则无法正确分配数据
imho你可以试试这个
<?php
if (!empty($all_student_record_info)):
foreach ($all_student_record_info as $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 is no data to display</strong>
</td>
<?php
endif;
?>
现在,如果您查看@your post array,您将看到您的数据按score_id分组(我假设这是所需的字段 - 因为您将其列为mysql示例中的第一项)