Data from a XML sheet is converted to php array and I have tried to create a quiz format question with the below code, but it does't work. Not sure how to get it working for multiple questions...
<?php
function get_answer($input){
if ($input == ($att['ans']) )
{echo
"Correct Answer . {$att['ans_desc']}";
}
else {
echo "Wrong Answer . {$att['ans_desc']}";
}
}
$xml = <<<XML
<dataroot>
<content id= "1">
<quest><![CDATA[<FONT FACE="Arial">Which of the following is not the measure of a physical quantity?</FONT>]]></quest>
<opt1><![CDATA[<FONT FACE="Arial">kilogram</FONT>]]></opt1>
<opt2><![CDATA[<FONT FACE="Arial">impulse</FONT>]]></opt2>
<opt3><![CDATA[<FONT FACE="Arial">energy</FONT>]]></opt3>
<opt4><![CDATA[<FONT FACE="Arial">density</FONT>]]></opt4>
<ans><![CDATA[a]]></ans>
<ans_desc><![CDATA[<FONT FACE="Arial">kilogram is the name of the fundamental unit of mass</FONT>]]></ans_desc>
</content>
</dataroot>
XML;
$data = new SimpleXMLElement($xml,LIBXML_NOCDATA);
$array = json_decode(json_encode($data),true);
foreach($array as $content => $att){
echo $att['quest'];
}
echo "<br />";
echo "<form name='quiz'> .
<input type=\"radio\" id='options' onclick = \"getAnswer({$att['ans']})\" />. {$att['opt1']} . <br />" .
"<input type=\"radio\" id='options' onclick = \"getAnswer({$att['ans']})\"/>. {$att['opt2']} . <br />" .
"<input type=\"radio\" id='options' onclick = \"getAnswer({$att['ans']})\"/>. {$att['opt3']} . <br />" .
"<input type=\"radio\" id='options' onclick = \"getAnswer({$att['ans']})\"/>. {$att['opt4']} . <br /> .
</form>";
?>