dongyuan2652 2012-04-27 19:21
浏览 14
已采纳

php多项选择测验创建者[关闭]

Here is the scenario,

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

  • the question
  • 1 correct answer
  • 4 incorrect answers

into the mysql database using a PHP form.

Here is what the table looks like

enter image description here

Now I would like to do two things:

  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>";

  2. 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?

All inputs appreciated.

  • 写回答

1条回答 默认 最新

  • dqvzfp6468 2012-04-27 19:45
    关注

    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>
    

    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!";
        }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度