php - 如何分离 PHP 中 while 循环中输出的复选框变量结果?

标签 php html forms

我正在尝试编写一个考勤系统,当用户出席类时,工作人员会选中一个复选框,然后程序会将相关客户的当前计数加一。问题是输出从 phpMyAdmin 获取的寄存器,它使用 while 循环,因此所有复选框都具有相同的变量名称。这是我到目前为止的代码...

echo "<form 'action=badminreg.inc.php' method='post'>";
      while ($row = mysqli_fetch_assoc($result)) {
        echo "<tr><td>".$row['bookingID']."</td><td>".$row['firstName']."</td><td>".$row['surname']."</td><td><input type='checkbox' name='present' value='present'</td><td><input type='checkbox' name='incident' value='incident'</td></tr>";
      }

      echo "<input type='submit' name='reg-submit'>";
      echo "</form>";
      isset($_POST['reg-submit']);
      $pres = $_POST['present'];

我需要分隔复选框输入,以便程序能够将各个用户与其他用户进行不同的标记。我对 PHP 有点陌生,因为这是我的 A-level 类(class)作业,所以有办法解决这个问题吗?任何帮助都会很棒。谢谢

最佳答案

您可以将复选框元素的名称定义为数组,并将 bookingID 作为值传递。

示例(未经测试):

$output = "<tr><td>{$row['bookingID']}</td><td>{$row['firstName']}</td><td>{$row['surname']}</td><td><input type='checkbox' name='present[]' value='{$row['bookingID']}'</td><td><input type='checkbox' name='incident[]' value='{$row['bookingID']}'</td></tr>";

变量 $_POST['present']$_POST['incident'] 包含一个包含所选复选框 ID 的数组。

关于php - 如何分离 PHP 中 while 循环中输出的复选框变量结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60036906/

相关文章:

php - Mysql从基于先前mysql资源的表中获取结果

java - iText:从 HTML 创建短语

php - 关于重定向应该如何工作的问题

html - 在不同的行上显示 radio 输入,但将文本与 radio 选择器保持在同一行

python - Django 表单,ModelMultipleChoiceField 上显示错误

php - 令人讨厌的流行 "No input file specified."与 nginx_php-fastcgi

javascript - SoundCloud Api - 如何制作(设置)播放列表收藏夹?

php - 使用 codeigniter 的 payfast 支付网关集成

html - 'textarea' 内的样式文本

javascript - 更改 Bootstrap 弹出窗口的属性