我有一个像这样的多项选择测验问题的 php 页面
<p>1. Is Manhattan near New York?<br>
<input type="radio" name="ans1" value="3">
Yes<br>
<input type="radio" name="ans1" value="2">
Maybe<br>
<input type="radio" name="ans1" value="1">
No</p>
<p>2. Do you like Indian food?<br>
<input type="radio" name="ans2" value="1">
Some times<br>
<input type="radio" name="ans2" value="3">
Never<br>
<input type="radio" name="ans2" value="2">
Always</p>
该页面向自身发布并检查答案是否正确
if($ans1 == "3") {
$test_complete .="Question one is <span class='green'>correct</span>, well done!<br/>";
}else{
$test_complete .="Question one is <span class='red'>incorrect</span>!<br/>";
}
// change the quest2 to the right answer
if($ans2 == "2") {
$test_complete .="Question two is <span class='green'>correct</span>, well done!<br/>";
}else{
$test_complete .="Question two is <span class='red'>incorrect</span>!<br/>";
}
现在,我不想告诉用户答案一或两个是正确的,而是运行一个计数器,它计算正确答案的数量和错误答案的数量,并将其显示在两个表格框中,一个框显示问题总数。