我正在构建测验项目。我想比较表格中的选定选项,然后将其与行值中的正确选项进行比较,然后进行比较。并计算正确的比较,然后回显出来。我是PHP和Mysql的新手。我该怎么做。 我正在尝试比较 我的表格如下
<div class="answer-quiz">
<form method="post">
<div>
<?php
$query = "SELECT * FROM quizzes WHERE quiz_add_id=32";
$select_question_quiz_query = mysqli_query($connection,$query);
if (!$select_question_quiz_query) {
die(mysqli_error());
}
while($row = mysqli_fetch_array($select_question_quiz_query)) {
$quiz_question = $row['quiz_question'];
$quiz_option_A = $row['quiz_option_A'];
$quiz_option_B = $row['quiz_option_B'];
$quiz_option_C = $row['quiz_option_C'];
$quiz_option_D = $row['quiz_option_D'];
$quiz_option_correct = $row['quiz_option_correct'];
?>
<div class="quiz-question-div"><?php echo $quiz_question; ?></div>
<div class="quiz-options">
<ul class="ul">
<li>
<span>
<input type="checkbox" name="box[]" value="optionA">
</span>
<span>
<?php echo $quiz_option_A; ?>
</span>
</li>
<li>
<span>
<input type="checkbox" name="box[]" value="optionB">
</span>
<span>
<?php echo $quiz_option_B; ?>
</span>
</li>
<li>
<span>
<input type="checkbox" name="box[]" value="optionC">
</span>
<span>
<?php echo $quiz_option_C; ?>
</span>
</li>
<li>
<span>
<input type="checkbox" name="box[]" value="optionD">
</span>
<span>
<?php echo $quiz_option_D; ?>
</span>
</li>
</ul>
</div>
<?php } ?>
</div>
<input type="submit" name="submit-quiz" class="btn-primary btn btn-lg final-submit">
</form>
</div>
我的PHP isset在下面
<?php
if(isset($_POST['submit-quiz'])) {
$box_array = $_POST['box'];
// selecting the correct option from the db
$query = "SELECT quiz_option_correct FROM quizzes WHERE quiz_add_id=32";
$select_question_quiz_query = mysqli_query($connection,$query);
$quiz_option_correct=array();
if (!$select_question_quiz_query) {
die(mysqli_error($connection));
}
for($i=0;$i<5 && ($row = mysqli_fetch_array($select_question_quiz_query, MYSQLI_BOTH));$i++) {
$quiz_option_correct[$i] = $row['quiz_option_correct'];
$box = $box_array[$i];
echo $quiz_option_correct[$i];
echo $box[$i];
}
// while($row = mysqli_fetch_array($select_question_quiz_query, MYSQLI_BOTH)) {
// $quiz_option_correct = $row['quiz_option_correct'];
//
// echo $quiz_option_correct;
//
// }
}
?>