We help IT Professionals succeed at work.
Get Started

QUIZ

anugb
anugb asked
on
434 Views
Last Modified: 2012-05-07
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

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE