【问题标题】:How to get the ID of all the checked boxes on displayed data base QUICKFIX?如何获取显示数据库QUICK FIX上所有复选框的ID?
【发布时间】:2014-12-22 09:51:04
【问题描述】:

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

【问题讨论】:

  • 只需检查一些值并提交表单,通过$_POST['questions']访问这些值
  • 对于POST,输入字段应位于form 标记中。

标签: php html mysql forms checkbox


【解决方案1】:

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

 $result = mysqli_query($con,"SELECT id,question,choiceA,choiceB,choiceC,choiceD,answer FROM q_and_a ");
  1. 然后在 while 块打开表单标签(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

    }

【讨论】:

  • 这更有效,但它总是说 id 为 4。当我点击 make test 时,你如何告诉我如何打印点击了哪些 id。我在选中 2 的情况下单击 make,它给了我 2 个 4
  • 我想我不明白你想要什么朋友
  • 在 for 循环执行后,id 被卡在 4,所以它只输出 4s。而不是一二三四。我想你没有测试你的代码,所以你显然不知道你在做什么。
猜你喜欢
  • 2012-03-29
  • 2011-08-21
  • 1970-01-01
  • 2020-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-26
  • 1970-01-01
相关资源
最近更新 更多