gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 23:30:55 24 4
gpt4 key购买 nike

我已经显示了数据库中的数据表,左侧有复选框。我想找到一种方法将复选框链接到问题编号 (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/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com