jquery - need help in quiz using php

668

hello i am developing a quiz using php , the script load quiz from quiz file not from mysql. i want to show one question per page

with next question ability . and when a quiz is done show me the results button goals :

  1. one question per page
  2. show me the result when quiz is done
  3. thanks for any help :)

i tried many ways to make it work but with no good idea

 <?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>
414

Answer

Solution:

The way I would approach this is with AJAX. Make a front facing page with your HTML. Start with question 1 and send answer to an ajax.php (name can be anything) using jQuery (http://api.jquery.com/jquery.ajax/).

In ajax.php process the answer to the original question and send back HTML for the second question and answer options as ajax response. Use jQuery's html method (http://api.jquery.com/html/) to integrate the html into your page dynamically.

Rinse and repeat. When done, return HTML with results. You can pass some parameters back and forth to keep track of what question you are on, answer totals, etc - depending on what you need.

People are also looking for solutions to the problem: php - Configure Phalcon Flash output to use specific session adapter

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.