私は最近、質問と回答を含む小さなプロジェクトに取り組んでいます。つまり、基本的には、このページを何と呼んでもクイズ/テストです。すべての質問と回答のストレージの要件に従ってデータベースを作成しました。そうそう、出力はデータベースから来ています。ここで、一度に 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
はラジオボタンの値を収集していました。