PHP的多项选择测验创作者 [英] php multiple choice quiz creator

查看:86
本文介绍了PHP的多项选择测验创作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是场景,

在我们的在线教育公司,我们正在创建一个在线测验. 管理员输入

At our online education firm we are creating an online quiz. The administrator feeds in

  • 问题
  • 1个正确答案
  • 4个错误答案

使用PHP表单进入mysql数据库.

into the mysql database using a PHP form.

这是桌子的样子

现在我想做两件事:

  1. 制作一个PHP页面,从表中检索10个随机问题/答案,并通过单选按钮将其显示在PHP页面上,所有这些都供用户检查正确的答案.

  1. Make a PHP page which retrieves let's say 10 random question/answers from the table and displays it on the PHP page with radio buttons and all for a user to check the right answer.

可以使用以下方法来显示检索到的信息吗?

Can the following method be used to display retrieved info?

echo "<td>" . $row['question'] . "</td>";
echo "<td>" . $row['c_answer'] . "</td>";
echo "<td>" . $row['w_answer1'] . "</td>";
echo "<td>" . $row['w_answer2'] . "</td>";
echo "<td>" . $row['w_answer3'] . "</td>";
echo "<td>" . $row['w_answer4'] . "</td>";

echo "<td>" . $row['question'] . "</td>";
echo "<td>" . $row['c_answer'] . "</td>";
echo "<td>" . $row['w_answer1'] . "</td>";
echo "<td>" . $row['w_answer2'] . "</td>";
echo "<td>" . $row['w_answer3'] . "</td>";
echo "<td>" . $row['w_answer4'] . "</td>";

再创建一个PHP页面,该页面检查用户提交的答案以及存储在数据库中的正确结果,并检查并创建记分卡的脚本.

Make a second PHP page which checks user submitted answer with the right results stored in the DB, script that checks and creates a scorecard.

我该如何执行这两项任务?

How can I go about doing the 2 tasks?

感谢所有投入.

推荐答案

这是经典的HTML表单.您的表单如下:

This is classic HTML forms. You have a form like this:

<?php
    $row = mysql_fetch_array(mysql_queryy('select * yourtable order by rand() limit 1'),MYSQL_ASSOC);
    $question = $row['question'];
    unset($row['question']);
    shuffle($row);
?>
<form method="post" action="other_script.php?q=<?php echo $question; ?>">
    <p><?php echo $question; ?></p>
    <?php
        foreach ($row as $key => $value) {
            echo "<input type='radio' name='answer'>".$value."</input>
            ";
        }
    ?>
    <input type="submit">Submit</input>
</form>

然后您的other_script.php页面将如下所示:

And then your other_script.php page would look like this:

<?php
    $ans = mysql_result(mysql_query('select c_answer from yourtable where question = "'.url_decode($_GET['q']).'"'),0);
    if ($_POST['answer'] == $ans){
        echo "You got it right!";
    }else{
        echo "You got it wrong!";
    }
?>

这篇关于PHP的多项选择测验创作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆