Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何生成随机测验问题并为其评分?_Php_Html - Fatal编程技术网

Php 如何生成随机测验问题并为其评分?

Php 如何生成随机测验问题并为其评分?,php,html,Php,Html,所以我需要的是给生成的随机问题打分。我不知道如何编写它。很难理解你的意思,但要在测验中加入随机问题,我将按如下方式构建它: 1) 将所有问题、答案和正确答案存储在MySQL数据库表中。 2) 数据库中有同一问题的多个版本。 3) 让PHP从数据库中随机选择问题的版本 4) 加载问题并用PHP为其构建HTML。我不知道如何编码。这就是问题所在。对于代码有问题的程序员来说,堆栈溢出是一种常见的错误。而不是找人替你工作。我知道想要一些东西但却做不到是令人沮丧的,那些能做的人也不想帮助你。很抱歉,如果我

所以我需要的是给生成的随机问题打分。我不知道如何编写它。

很难理解你的意思,但要在测验中加入随机问题,我将按如下方式构建它: 1) 将所有问题、答案和正确答案存储在MySQL数据库表中。 2) 数据库中有同一问题的多个版本。 3) 让PHP从数据库中随机选择问题的版本
4) 加载问题并用PHP为其构建HTML。

我不知道如何编码。
这就是问题所在。对于代码有问题的程序员来说,堆栈溢出是一种常见的错误。而不是找人替你工作。我知道想要一些东西但却做不到是令人沮丧的,那些能做的人也不想帮助你。很抱歉,如果我遇到有点苛刻的话。但试着从我们的角度来看:如果我们为你做这件事,你将一无所获。我们毫无理由地在这上面花费了宝贵的时间。因为下一次你需要什么的时候,你只要再问一次就行了。所以,开始学习吧!一旦你学会了,你可以自己做。没有更多的挫折。当然,当您的代码出现特定问题时,也会出现这种情况!
<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>";

?>
select*from (select*from quiz where level between 1 and 10 order by rand()) tmp group by level order by level