dousi4148 2015-03-03 14:34
浏览 49
已采纳

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

i am fetching data to create a form that would later be updated via php into their individual mysql rows. 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

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'");
    }
}
  • 写回答

1条回答 默认 最新

  • dounang1974 2015-03-03 15:55
    关注

    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'");
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大