我正在获取数据以创建一个表单,稍后将通过 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'");
}
}
最佳答案
我不完全理解这个问题,但这就是你想要的吗?结果数组的大小是否相同,并且它们之间的键是否匹配?
if(isset($_POST['submit']))
{
foreach($_POST['std_id'] as $key => $student)
{
mysql_query("update result set ca1='{$_POST['ca1'][$key]}' where student_id='$student'");
}
}
关于php - 将多个php表单数组插入mysql行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28834452/