需要帮助测验使用PHP

时间:2015-01-17 02:11:16

标签: php jquery

你好我正在使用php开发一个测验,该脚本从测验文件加载测验而不是来自mysql。我想在每页显示一个问题

具有下一个问题的能力。当测验完成后,显示结果按钮 目标:

  1. 每页一个问题
  2. 在测验完成时告诉我结果
  3. 感谢您的帮助:)。
  4. 我尝试了许多方法让它发挥作用但没有好主意

     <?php
    // This script displays the quiz selected
    
    // Display the header
    
    // concatenate the target path from the parent dir path
    
    
    $quiz = $_GET['q'];
    $this_dir = dirname(__FILE__);
    $parent_dir = realpath($this_dir . '../');
    $target_path = $parent_dir . '/tests/';
    $quizfile =$target_path+$quiz.'.qz';
    if (file_exists($quizfile)){
    include(htmlspecialchars($quizfile));
    echo "<h2>$title</h2>";
    }else{ 
    die();
    }
    ?>
    
    <center>
    <form action="quizresults.php?quiz=<? echo $quiz ?>" method=post>
    <table border=0 width="100%">
    <?
    
    // Show all the questions and allow the user to select answers
    for ($i=0; $i<$questions; $i+=1)
    {
    ?>
        <tr>
          <td colspan=2 bgcolor="#999999"><font color="#000000"><? echo $question[$i]; ?></font></td>
        </tr>
    <?
        for ($j=0; $j<$types; $j+=1)
        {
    ?>
            <tr>
                <td valign=top width=1><input type="radio" name="q_<? echo $i+1; ?>" value="<? echo $j+1; ?>">
                <td><? echo $answer[$i][$j]; ?></td>
            </td></tr>
    <?
        }
    }
    ?>
    </TABLE>
    <BR><BR>
    <input type="submit" value="show results !"></center>
    </form>
    

1 个答案:

答案 0 :(得分:0)

我接近这个的方式是使用AJAX。使用HTML制作一个面向前方的页面。从问题1开始,使用jQuery(http://api.jquery.com/jquery.ajax/)将答案发送到ajax.php(名称可以是任何内容)。

在ajax.php处理原始问题的答案,并将第二个问题和答案选项的HTML发回作为ajax响应。使用jQuery的html方法(http://api.jquery.com/html/)动态地将html集成到您的页面中。

冲洗并重复。完成后,返回带有结果的HTML。您可以来回传递一些参数来跟踪您所处的问题,回答总数等 - 具体取决于您的需求。

相关问题