我一直在研究最近涉及问题和答案的小项目。所以基本上这是一个测验/测试,无论你打电话给这个页面。我根据需要为所有问题和答案存储制作了一个数据库。所以是的,输出来自数据库。现在,我需要在页面中一次输出5个问题,因此使用分页来完成。如何在分页期间收集单选按钮值?
$outputList = '';
while($row = mysql_fetch_array($sql2)){
$question = $row['questions'];
$opta = $row['optA'];
$optb = $row['optB'];
$optc = $row['optC'];
$optd = $row['optD'];
$id = $row['ctrlNo'];
$outputList .="
<p>$id. $question</p>
<div>
<input type='radio' name='question-$id-' id='question-$id-answers-A' value='A' />
<label for='question-$id-answers-A'>A) $opta </label>
</div>
<div>
<input type='radio' name='question-$id-' id='question-$id-answers-B' value='B' />
<label for='question-$id-answers-B'>B) $optb </label>
</div>
<div>
<input type='radio' name='question-$id-' id='question-$id-answers-C' value='C' />
<label for='question-$id-answers-C'>C) $optc </label>
</div>
<div>
<input type='radio' name='question-$id-' id='question-$id-answers-D' value='D' />
<label for='question-$id-answers-D'>D) $optd </label>
</div>
";
}
好的,所以我有4个单选按钮来选择每个问题,他们都完美地工作。我无法弄清楚的是在分页过程中收集他们的价值。我的意思是,当我在页面1上提交我的答案时,它正在工作,但是当我转到第2页并提交答案时,它不会传递从第1页收集的值。现在,我正在想法如何做到这一点。任何人都可以引导我,我可以做什么来收集选定的单选按钮的所有值,从页面1到用户的当前页面,并将其传递到我的PHP页面,验证答案?这是我的HTML代码。
<form id="form1" name="form1" action="testpage5.php" method="POST" >
<?php print "$outputList"; ?>
<p><div style="margin-left:58px; margin-right:58px; padding:6px; background- color:#FFF; ">
<?php echo $paginationDisplay; ?>
</div></p>
<input type="submit" value="Submit Quiz"></input>
</form>`
testpage5.php
是我验证比较$_POST
值从数据库中正确答案的答案页面。我用$_POST
来收集单选按钮的值。
非常感谢Voitcus编辑我的文章。我在这里是新的,并不知道使用哪些命令来使这些代码尽可能呈现。 hehehe :) – don 2013-03-12 08:36:01