php - 如何获取显示的数据库QUICKFIX上所有复选框的ID?

标签 php html mysql forms checkbox

我已经显示了数据库中的数据表,左侧有复选框。我想找到一种方法将复选框链接到问题编号 (ID)。当我点击提交时,我希望回显所选的 id。我非常希望有人能够选择他们想要的问题然后显示它们。

  <?php

    $con=mysqli_connect("####","####","#####","###");

   $result = mysqli_query($con,"SELECT * FROM q_and_a ");

 echo "<table border='1'>
  <tr>
<th>Add</th>
<th>#</th>
<th>Question</th>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>Answer</th>

</tr>";

while($row = mysqli_fetch_array($result))
 {
 echo "<tr>";

echo '<td><input type="checkbox" name="questions[]" value="$id"></td>';

echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['question'] . "</td>";
echo "<td>" . $row['choiceA'] . "</td>";
echo "<td>" . $row['choiceB'] . "</td>";
echo "<td>" . $row['choiceC'] . "</td>";
echo "<td>" . $row['choiceD'] . "</td>";
echo "<td>" . $row['answer'] . "</td>";
echo "</tr>";
 }
 echo "</table>";

mysqli_close($con);

?>

提交按钮

<form  method="POST" action="makeTest.php">
<input type="submit" name="make" value="Make Test">
</form>

最佳答案

对您的代码进行一些编辑,然后它就会起作用。 1.通过添加非*字段来更改查询(以确保性能和显示顺序)

 $result = mysqli_query($con,"SELECT id,question,choiceA,choiceB,choiceC,choiceD,answer FROM q_and_a ");
  • 然后在 while block 打开表单标签之前(HTML)

    <?php 
     //above codes will be there as you show before 
    echo '<form  method="POST" action="makeTest.php">';
    while($row = mysqli_fetch_array($result)){
    { $id=$row['id'];  // initialize your id here, so as to pass it in checkbox too
     // then continue with your code
    }
    ?>
    <input type="submit" name="make" value="Make Test">
    </form>
    
  • 在 maketest.php 中,你可以使用 foreach 处理 ckeckbox,见下文

        foreach($_POST['questions'] as $questions){
                              //do your job
    
        }
    

    关于php - 如何获取显示的数据库QUICKFIX上所有复选框的ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26583815/

    相关文章:

    php - 给出警告 : mysql_result() expects parameter 1 to be resource, bool 值

    javascript - 将值从一个页面的ajax函数传递到另一页面的ajax函数

    mysql - 错误 1062 (23000) : Duplicate entry though entries are not duplicate

    MySql存储过程WHERE "variabilised"根据参数

    日期的 MySQL 字段类型,格式为 YYYYMM

    php - 如何在类之外显示来自数据库的数据

    php - XAMPP 7.0.6 中的 api-ms-win-crt-runtime-l1-1-0.dll 丢失错误

    php - 尝试在 laravel 5.5 中获取非对象的属性

    html - 我无法让这个下拉菜单与 CSS 一起使用

    html - 如何让这个内部div垂直居中? (使用CSS)