-2
XML 시트의 데이터가 PHP 배열로 변환되고 아래 코드로 퀴즈 형식 질문을 만들려고했지만 작동하지 않습니다. 확실하지 만약 내가 잘못코드를 객관식 퀴즈 형식으로 변환
<?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>";
?>
"작동하지 않는다"는 것이 도움이되지 않습니다. 작동하지 않는 것은 무엇입니까? 어떤 기능이 누락 되었습니까? – Amaerth
AJAX 호출없이 PHP를 클라이언트 측에서 효과적으로 실행하려고합니다. 그리고 그것은 단지 이런 식으로 작동하지 않습니다. 대신 (아마도) 서버에 응답을 제출하고 JavaScript로 응답을 구문 분석해야합니다. – raina77ow