简体   繁体   English

将多个php表单数组插入mysql行

[英]insert mutiple php form array into mysql rows

i am fetching data to create a form that would later be updated via php into their individual mysql rows. 我正在获取数据以创建一个表单,该表单稍后将通过php更新到他们各自的mysql行中。 Here is what i have tried so far and it isn't working. 这是我到目前为止尝试过的,但它无法正常工作。

$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 } ?>

and here is how I intend to process it so that each Students CA1 is updated accordingly 以下是我打算如何处理它以便相应地更新每个学生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'");
    }
}

I don't fully understand the question but is this what you are wanting? 我不完全理解这个问题,但这是你想要的吗? Are the result arrays the same size and keys match up between them? 结果数组的大小是否相同,键之间是否匹配?

if(isset($_POST['submit']))
{

    foreach($_POST['std_id'] as $key => $student)
    {
         mysql_query("update result set ca1='{$_POST['ca1'][$key]}' where student_id='$student'");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM