<form action="grade.php" method="post" id="quiz">
... questions here ... ....Question 1.... <li>
<h3>CSS Stands for...</h3>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-A" value="A" />
<label for="question-1-answers-A">A) Computer Styled Sections </label>
</div>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-B" value="B" />
<label for="question-1-answers-B">B) Cascading Style Sheets</label>
</div>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-C" value="C" />
<label for="question-1-answers-C">C) Crazy Solid Shapes</label>
</div>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-D" value="D" />
<label for="question-1-answers-D">D) None of the above</label>
</div>
</li> ....question 2.... <li>
<h3>CSS Stands for...</h3>
<div>
<input type="radio" name="question-2-answers" id="question-2-answers-A" value="A" />
<label for="question-2-answers-A">A) Computer Styled Sections </label>
</div>
<div>
<input type="radio" name="question-2-answers" id="question-2-answers-B" value="B" />
<label for="question-2-answers-B">B) Cascading Style Sheets</label>
</div>
<div>
<input type="radio" name="question-2-answers" id="question-2-answers-C" value="C" />
<label for="question-2-answers-C">C) Crazy Solid Shapes</label>
</div>
<div>
<input type="radio" name="question-2-answers" id="question-2-answers-D" value="D" />
<label for="question-2-answers-D">D) None of the above</label>
</div>
</li><input type="submit" value="Submit Quiz" /></form> <?php
$answer1 = $_POST['question-1-answers'];
$answer2 = $_POST['question-2-answers'];
$answer3 = $_POST['question-3-answers'];
$answer4 = $_POST['question-4-answers'];
$answer5 = $_POST['question-5-answers'];
$totalCorrect = 0;
if ($answer1 == "B") { $totalCorrect++; }
if ($answer2 == "A") { $totalCorrect++; }
if ($answer3 == "C") { $totalCorrect++; }
if ($answer4 == "D") { $totalCorrect++; }
if ($answer5) { $totalCorrect++; }
echo "<div id='results'>$totalCorrect / 5 correct</div>";
?>
我的测验问题是静态的,即用户可以做一些谷歌搜索来回答我不想要的问题,所以我想生成随机问题,然后给他们打分,但不知道怎么做。我想使用数据库rand()
问题。我已经有了这个从数据库生成10个随机问题:
select*from (select*from quiz where level between 1 and 10 order by rand()) tmp group by level order by level
所以我需要的是对生成的随机问题进行评分。我不知道如何编码。
答案 0 :(得分:0)
很难理解你的意思,但是要将随机问题包含在测验中,我会按如下方式构建它: 1)将所有问题,答案和正确答案存储在MySQL数据库表中。 2)在数据库中有相同问题的多个版本。 3)让PHP从数据库中选择问题的随机版本 4)加载问题并使用PHP为它们构建HTML。