如何在另一个页面中使用 while 循环 PHP 中的单选按钮值


How to get the Radio Button values in another page using while loop Concept in php

如何使用循环概念在 php 中获取和存储 MysqlDatabase 中的单选按钮值

$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_row($result)) 
{
     ?>                                       
     <tr><form action="update_attendance.php?amid=<?php$row[0];?>&amp;amname=<?php echo $row[1];?>" method="POST">
       <td><?php echo $row[0]; ?></td>
       <td><?php echo date('d-M-Y'); ?></td>
       <td><?php echo $row[1]; ?></td>
       <td><?php echo $row[6]; ?></td>                         
       <td> 
            <input type="radio" name="status" value="Present" checked="checked">Present &nbsp;&nbsp;&nbsp;</input>
            <input type="radio" name="status" value="Permission">Permission</input>
            <input type="radio" name="status" value="Absent">Absent</input>
       </td>
       <td>
            <input type="submit" value="Update" class="btn btn-success btn-medium">
       </td>
     </form>

您的代码会生成许多名为"status"的单选按钮。您需要使每组单选按钮都具有唯一的名称。

您可能正在查询的表中的一列是唯一的 id 列。

您可以在输入名称中设置id(在这种情况下可能$row[0]),如下所示:

<input type="radio" name="status[<?php echo $row[0] ?>]" value="a">a</input>
<input type="radio" name="status[<?php echo $row[0] ?>]" value="b">b</input>
<input type="radio" name="status[<?php echo $row[0] ?>]" value="c">c</input>

并在表单提交后在您的 php 文件中检查var_dump($_POST['status']).您将看到所有值都以数组形式提供。