Select 单选行和更新 table

Select row with radio and update table

我有一个 table,其中 select 行带有单选按钮,当单击按钮时,状态在 mysql table 中更新,但是当我单击按钮时,最后一个用户已更新,其他用户未更新。

 <form method="post" accept-charset="utf-8" name="frmUser" >
 <table>
  <thead>
   <tr>
    <th>Status</th>
   </tr>
  </thead>
  <tbody>
   <?php
      $qr=$mysqli->query("SELECT * FROM `user`");
       while($row=$qr->fetch_object()){
    ?>
   <tr>
    <td><input type="radio" name="users[]" value="<?php echo $row->id; ?>">
     </input></td>
    <td class="blck min"><?php echo $row->status; ?></td>
    <td><span>
     <input type="submit" value="" id="st" name="st">
     <?php
          if(isset($_POST['st'])){
           $rowCount = count($_POST["users"]);
            for($i=0;$i<$rowCount;$i++) {
            if($row->status == 'ENABLE'){
            $mysqli->query("UPDATE `user` SET `status`='DISABLE' WHERE `id`='" . $_POST["users"][$i] . "'");
            }
            else{
            $mysqli->query("UPDATE `user` SET `status`='ENABLE' WHERE `id`='" . $_POST["users"][$i] . "'");
            }
            }
            header("location:users.php");
            }
         ?>
     </span></td>
   </tr>
   <?php}?>
  </tbody>
 </table>
</form>

请放在下面一行并检查显示了多少计数:

$rowCount = count($_POST["users"]);
print('<pre>COUNT :: ' . $rowCount . ' >> ');
print_r($_POST["users"]);
print('</pre>');exit;

以上代码仅显示您的计数值。

让我知道更多帮助!