我正在获取数据以创建一个表单,该表单稍后将通过php更新到他们各自的mysql行中。这是我到目前为止所尝试的,但它无法正常工作。
$subj='1';
while($row=mysql_fetch_assoc($sql))
{
$go=mysql_query("select 1ca from result where subject_id='$subj' and student_id='$row[id]'"); $ca=mysql_fetch_assoc($go);
?>
<tr><td><input type="hidden" name="std_id[]" value="<?php echo $row['id']; ?> "/><?php echo $row['firstname']; ?> <?php echo $row['lastname']; ?></td>
<td><input type="text" name="ca1[]" value="<?php echo $ca['1ca']; ?>"/></td></tr>
<?php } ?>
以下是我打算如何处理它以便每个学生CA1相应更新
if(isset($_POST['submit']))
{
foreach($_POST['std_id'] as $student)
{
foreach ($_POST['ca1'] as $ca1)
{
}
mysql_query("update result set ca1='$ca1' where student_id='$student'");
}
}
答案 0 :(得分:0)
我不完全理解这个问题,但这是你想要的吗?结果数组的大小是否相同,键之间是否匹配?
if(isset($_POST['submit']))
{
foreach($_POST['std_id'] as $key => $student)
{
mysql_query("update result set ca1='{$_POST['ca1'][$key]}' where student_id='$student'");
}
}