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

while loop result at table, sends first row when submit form in php

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

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

此代码的结果

2.when 点击编辑 link 每次第一个 id which 16 throw by form

我需要,当按 link 在 id 17 编辑然后 id 17 由表单抛出

如果有帮助,请尝试以下操作:

<?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 值的唯一性,您可以做的是,为每个 table 行附加 $row['id']euser。此外,您忘记将每个 table 行封装在 <tr>...</tr> 中。所以你的代码应该是这样的:

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