<?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";
}
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.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE