Link to home
Get AccessLog in
Avatar of anugb
anugb

asked on

QUIZ

Hi,

I have quiz , where questions has to  displayed in seperate pages and once the answer is selected the user can see the number of correct responses using a poll graph. How can i do this??
The data is from a Xml file
<?php 
error_reporting(E_ALL);
 
// TEST DATA - ASSUMING THAT THIS IS THE CONTENTS OF THE topic.xml FILE
 
$tobj = simplexml_load_file('topic.xml');
$qobj = simplexml_load_file('questions.xml');
 
 
 
 
// IF NOTHING WAS POSTED YET
if (empty($_POST["choice"]))
{
    // PUT UP THE HTML FORM TO RECEIVE THE CHOICE
    echo "PLEASE CHOOSE";
        echo "<form method=\"post\">\n";
 
        // ITERATE OVER THE OBJECT TO PRODUCE THE HTML FORM FIELDS
        foreach($tobj->children() as $child)
        {
            echo "<br/><input type=\"radio\" name=\"choice\" value=\"{$child['topic']}\" />";
            echo $child["title"];
            echo "\n";
        }
 
        // CLOSE OUT THE FORM
        echo "<br/><input type=\"submit\" value=\"Choose\" />\n";
        echo "</form>\n";
}
 
 
 
 
// IF ANYTHING WAS POSTED
if (!empty($_POST["choice"]))
{
    $found = FALSE;
    $q_choice = $_POST["choice"];
    echo "<br/>YOU CHOSE: $q_choice<br/>\n";
 
    // ITERATE OVER THE OBJECT TO PRODUCE THE OUTPUT FROM THIS CHOICE
    foreach ($qobj as $record)
    {
        // IF THE TOPIC FROM THE FORM MATCHES THE TOPIC IN THE RECORD
        if ($q_choice == $record["topic"])
        {
            echo "<br/><br/>$record->title";
            echo "<br/>$record->question";
            foreach($record->choices->children() as $choice)
            {
                echo "<br/><input type=\"radio\" name=\"$record->title\" value=\"{$choice['choice']}\" />";
                echo " ".$choice;
            }
            echo "<br/><input type=\"submit\" value=\"Choose\" / >\n";
 
            // ADD OTHER ITERATORS AND TESTS HERE AS NEEDED
            $found = TRUE;
        }
    } // END ITERATOR
 
    // IF NOTHING WAS FOUND
        if (!$found) echo "<br/>NOTHING FOUND TO MATCH $q_choice\n";
}

Open in new window

Avatar of Michael701
Michael701
Flag of United States of America image

So far your code looks great. When they answer the quiz questions the data will appear in the $_POST[] array.

Looks like you'll have to loop thru the $_POST array and count the number of correct answers.

If you're stuck on a specific line of code, post what you have and the error (or description of the problem) and we can help.
Avatar of anugb
anugb

ASKER

At line 28 and 29 I am printing the questions in a single page.. The questions are from an external xml file. Now i want them to be printed in a seperate page.. How should i proceed??
ASKER CERTIFIED SOLUTION
Avatar of Michael701
Michael701
Flag of United States of America image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Avatar of anugb

ASKER

Its little confusing.. Can u please explain it more clearly
well make that program change and you should see that it will only display the first question.

Then add code to check the answer and display the next question (if there is one) if there are no more questions then display the chart
Avatar of anugb

ASKER

Well I tried to print.. I am not able to come up with solid answer :((
Please upload the topics and questions files and post your most recent code. I'll set it up on my test server.