troubleshooting Question

QUIZ

Avatar of anugb
anugb asked on
PHPXMLWeb Applications
7 Comments1 Solution436 ViewsLast Modified:
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

ASKER CERTIFIED SOLUTION
Michael701

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros