在php/mysqli中设置表单
我正在做这个测验。但是我的状态有点问题。该页面显示一个随机问题,但不是显示4个不同的答案选项,而是将一个选项重复4次。我该如何着手解决这个问题在php/mysqli中设置表单,php,html,forms,mysqli,Php,Html,Forms,Mysqli,我正在做这个测验。但是我的状态有点问题。该页面显示一个随机问题,但不是显示4个不同的答案选项,而是将一个选项重复4次。我该如何着手解决这个问题 <?php //retrieve question list: $get_questions = $con->prepare("SELECT question_ID, question FROM questions"); $get_questions->execute(); $get_questi
<?php
//retrieve question list:
$get_questions = $con->prepare("SELECT question_ID, question FROM questions");
$get_questions->execute();
$get_questions->bind_result($question_ID, $question);
$questions = array();
while ($get_questions->fetch()) {
$questions[$question_ID] = array($question_ID, $question, array());
}
// retrieve answer list:
$get_answers = $con->prepare("SELECT id, question_ID, answers, correct FROM answers");
$get_answers->execute();
$get_answers->bind_result($id, $question_ID, $answers, $correct);
while ($get_answers->fetch()) {
$questions[$question_ID][2][$id] = array($id, $answers, $correct);
}
// Scramble the array and print:
shuffle($questions);
?>
<form method="get" action="result.php">
<div class="question">
<label><h2><?php echo $question ?></h2></label>
<br>
<input type="hidden" name="question<?php echo $question_ID ?>_id" value="<?php echo $question_ID; ?>" id="question<?php echo $question_ID; ?>_id"/>
<input name="answer<?php echo $id ?>" id="q<?php echo $id ?>_a1" value="1" type="radio"/>
<label for="q<?php echo $id ?>_a1"> <?php echo $answers ?></label><br>
<input name="answer<?php echo $id?>" id="q<?php echo $id ?>_a2" value="2" type="radio"/>
<label for="q<?php echo $id ?>_a2"> <?php echo $answers ?></label><br>
<input name="answer<?php echo $answers ?>" id="q<?php echo $id ?>_a3" value="3" type="radio"/>
<label for="q<?php echo $id ?>_a3"> <?php echo $answers ?></label><br>
<input name="answer<?php echo $id ?>" id="q<?php echo $id ?>_a4" value="4" type="radio"/>
<label for="q<?php echo $id ?>_a4"> <?php echo $answers ?></label><br>
</div>
<?php
echo "<br><input name=\"submit\" type=\"submit\" value=\"Submit\">";
echo "</form></body></html>";
?>
</form>
</html>
</body>
您每次都回显$answers
,但是$answers
没有在任何地方定义。表单是否以循环方式显示?您是否在脚本的其他地方定义了变量?如果是这样,我们也需要这些。我相信您需要了解PHP变量是如何工作的。您正在重复回显同一个变量!为什么不从$questions
数组中获取它们?我刚刚开始使用phpmyadmin。不,我的表单当前不在循环中。我没有在其他地方定义变量。我试图调用数据库中答案表中的选项,但我突然想到该表和我试图调用的列具有相同的名称>。因此,我们基本上是在帮助您在测验中获得A,对吗?听起来像是学术上的不诚实@我只是希望更正我已经编写的代码,我不会要求任何人为我重写它。