【发布时间】:2013-03-18 16:40:26
【问题描述】:
我正在尝试根据我找到的教程创建一个简单的测验。 http://css-tricks.com/building-a-simple-quiz/
不幸的是,这让我在旋转我的车轮,答案可能很简单。
我得到了这个完美的工作。我想更改功能。我希望它做其他事情,而不是计算答案。
- 我想再次显示问题。
- 还有,选择的答案和正确的答案。回显答案,不是字母 A、B、C、D。
在我看来,做一个小测验并说你错过了 2 个而不显示错过了哪些问题。
我宁愿避免使用数据库。它可以在屏幕上、在新屏幕上或通过电子邮件发送。没有偏好。有什么建议吗?
这是来自上述网站的代码:
<form action="grade.php" method="post" id="quiz">
<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>
</form>
<input type="submit" value="Submit Quiz" />
然后是 PHP 脚本:
<?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>";
?>
任何建议或链接将不胜感激。我的谷歌技能让我失望了。我想搜索的所有内容都会带来不相关的内容。
【问题讨论】:
-
您必须找到一种方法将
grade.php中的函数合并到index.php测验文件中,并将表单操作设置为$_SERVER['PHP_SELF'];,和/或在某处设置include file那里(也许在一个 DIV 中)有测验问题。除此之外,它还需要一些漂亮的编码。我可能会成功,但这需要我一些时间。好问题。