我是 php 新手,几天来一直在努力寻找答案。我有一个使用表单内的 while 循环动态创建的学生列表。然后我添加了一个输入框,以便我可以在那里提交成绩。这很好用。
<form action="<? $_SERVER['PHP_SELF']; ?>" method="POST" name="assignments" id="assignments">
<?php
while($row_students = mysql_fetch_array($students))
{ ?>
<input grade="grade[]" type="text" size="3" />
<? echo $row_students['student_number'];?>
<input name="student_id[]" type="hidden" value="<? echo $row_students['student_number']; ?>" />
<? echo $row_students['student_name'] ; ?>
<input name="assignment_name[]" type="hidden" value="<? echo $row_assignments['assignment_name'];?>" /><br/>
<? }
?>
<br/>
<input name="submit" type="submit" value="submit" />
| <a href="index.php">Cancel</a>
</form>
当我 print_r 发布数据时,我得到:
Array
(
[0] => Array
(
[0] => assignment 1
[1] => assignment 1
[2] => assignment 1
[3] => assignment 1
[4] => assignment 1
[5] => assignment 1
[6] => assignment 1
[7] => assignment 1
)
[1] => Array
(
[0] => 432100312
[1] => 432100351
[2] => 432100353
[3] => 432100354
[4] => 432100355
[5] => 433536343
[6] => 436253636
[7] => 473634728
)
[2] => Array
(
[0] => 21
[1] => 21
[2] => 33
[3] => 42
[4] => 15
[5] => 26
[6] => 37
[7] => 18
)
)
我的问题现在是两个方面。我认为它应该显示如下:
[0] => Array
(
[0] => assignment 1
[0] => 432100312
[0] => 21
)
因为我想使用这些数据将每个集合插入到具有以下字段的数据库中 - assignment_name、student_id 和 _grade。
我也尝试了几个插入循环无济于事,因此这篇文章。