在表中循环结果时,在php中提交表单时发送第一行

在表中循环结果时,在php中提交表单时发送第一行,php,forms,while-loop,submit,Php,Forms,While Loop,Submit,1.获取用户数据并以表格形式显示 <?php while($row=mysqli_fetch_assoc($rResultSet)) { ?> <td><?php echo $row['id']?></td> <

1.获取用户数据并以表格形式显示

                  <?php
                      while($row=mysqli_fetch_assoc($rResultSet))
                     {
                   ?>

                  <td><?php echo $row['id']?></td>
                  <td><?php echo $row['name']?></td>
                  <td><?php echo $row['user_role']?></td>
                  <td><?php echo $row['start_date']?></td>
                  <td>

                  <form id='euser' action='edituser.php' method='post'>
                  <input type="hidden" name="id" value="<?php echo $row['id']?>">
                  <input type="hidden" name="type" value="edituser">

                  <a  href="javascript: document.getElementById('euser').submit();">Edit</i></a>|
                 </form>
                 <?php 
                 }
                 ?>

如果有帮助,请尝试以下内容:

<?php
    while($row=mysqli_fetch_assoc($rResultSet))
{
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['user_role'];?></td>
<td><?php echo $row['start_date'];?></td>
<td>

    <form id='<?php echo $row['id'];?>' action='edituser.php' method='post'>
        <input type="hidden" name="id" value="<?php echo $row['id'];?>">
        <input type="hidden" name="type" value="edituser">

        <a  href="javascript: document.getElementById('<?php echo $row['id'];?>').submit();">Edit</a>|
    </form>
</td>
</tr>
 <?php 
   }
 ?>


问题是由于表单的
id
属性,它必须对每一行都是唯一的。现在,您正在为每一行分配相同的id值
euser
。为了保持
id
值的唯一性,您可以为每个表行附加
$row['id']
euser
。另外,您忘了将每个表行封装在
中。因此,您的代码应该如下所示:

<?php
    while($row=mysqli_fetch_assoc($rResultSet)){
    ?>
        <tr>
            <td><?php echo $row['id']?></td>
            <td><?php echo $row['name']?></td>
            <td><?php echo $row['user_role']?></td>
            <td><?php echo $row['start_date']?></td>
            <td>

            <form id='euser<?php echo $row['id']?>' action='edituser.php' method='post'>
                <input type="hidden" name="id" value="<?php echo $row['id']?>">
                <input type="hidden" name="type" value="edituser">

                <a  href="javascript: document.getElementById('euser<?php echo $row['id']?>').submit();">Edit</i></a>|
            </form>
        <tr>
    <?php 
    }
?>


现在单击“编辑”时的结果是什么?请使用类而不是id。
id
值必须是唯一的。因此,当您每次单击“编辑”时,它都会获得表单第一次出现的元素id,其中
id=“euser”
。添加任何编辑属性,如数据id=“.id.”。在错误日志中,我会检查16的值(始终为第一个值)按表单发送单击“编辑”时得到的值。。。我看见你在这里躲藏。