在php / mysqli中设置表单

时间:2014-05-06 23:30:40

标签: php html forms mysqli

我正在进行这个测验。但是我的表格出了问题。该页面显示一个随机问题,但不是显示4个不同的答案选项,而是重复一次选项4次。我该如何解决这个问题?

    <?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>

0 个答案:

没有答案