私はオンライン試験システムを構築しようとしています。私はデータベースから質問を取り出して一つずつ表示したいのです。つまり、ユーザーは次の質問を見るために「次へ」をクリックします。私はJQueryを使いたい。何か案は?PHPオンライン試験
は、ここに私のPHPコードデータベースは20の以上の質問があり
$getTests = $conn->prepare("SELECT * FROM grammar_test WHERE active = ? ORDER BY RAND() LIMIT 20");
$getTests->execute(array(1));
$rowTests = $getTests->fetch(\PDO::FETCH_ASSOC);`
ですが、私は唯一の20のランダムな質問をしたいです。ここで
はHTMLである(2つのフィールドセットにTrancatedが、彼らは実際には20です)<form action="" class="grammar-test-form " method="POST" accept-charset="utf-8">
<fieldset id="first">
<?php if(!empty($rowTests['instructions'])){ echo '<h4>1. '.$rowTests['instructions'].'</h4>';}?>
<?php if(!empty($rowTests['question'])){ echo '<h4>'.$rowTests['question'].'</h4>';}?>
<?php if(!empty($rowTests['instructions'])){ echo '<input type="radio" name="'.$rowTests['question_id'].'"> '.$rowTests['choice_1'].'<br/>';}?>
<?php if(!empty($rowTests['instructions'])){ echo '<input type="radio" name="'.$rowTests['question_id'].'"> '.$rowTests['choice_2'].'<br/>';}?>
<?php if(!empty($rowTests['instructions'])){ echo '<input type="radio" name="'.$rowTests['question_id'].'"> '.$rowTests['choice_3'].'<br/>';}?>
<?php if(!empty($rowTests['instructions'])){ echo '<input type="radio" name="'.$rowTests['question_id'].'"> '.$rowTests['choice_4'].'<br/>';}?>
<hr/>
<button class="next_btn btn btn-3d btn-green" name="next" type="button">Next »</button>
</fieldset>
<fieldset>
<?php if(!empty($rowTests['instructions'])){ echo '<h4>2. '.$rowTests['instructions'].'</h4>';}?>
<?php if(!empty($rowTests['question'])){ echo '<h4>'.$rowTests['question'].'</h4>';}?>
<?php if(!empty($rowTests['instructions'])){ echo '<input type="radio" name="'.$rowTests['question_id'].'"> '.$rowTests['choice_1'].'<br/>';}?>
<?php if(!empty($rowTests['instructions'])){ echo '<input type="radio" name="'.$rowTests['question_id'].'"> '.$rowTests['choice_2'].'<br/>';}?>
<?php if(!empty($rowTests['instructions'])){ echo '<input type="radio" name="'.$rowTests['question_id'].'"> '.$rowTests['choice_3'].'<br/>';}?>
<?php if(!empty($rowTests['instructions'])){ echo '<input type="radio" name="'.$rowTests['question_id'].'"> '.$rowTests['choice_4'].'<br/>';}?>
<hr/>
<button class="pre_btn btn btn-3d btn-green" name="previous" type="button">Previous</button>
<button class="next_btn btn btn-3d btn-green" name="next" type="button">Next »</button>
</fieldset>
</form>
はここで別の
$(document).ready(function() {
$(".next_btn").click(function() {
$(this).parent().next().fadeIn('slow');
$(this).parent().css({
'display': 'none'
});
$('.active').next().addClass('active');
});
$(".pre_btn").click(function() {
$(this).parent().prev().fadeIn('slow');
$(this).parent().css({
'display': 'none'
});
$('.active:last').removeClass('active');
});
});
すべて1つのフィールドセットから移動することはJQueryで正常に動作します。問題は1つの質問が選択され、20回繰り返されることです。私は20種類の質問をしたい。何か案が? whileループのアイデアがありますが、最初と最後のフィールドセットで問題が発生します。最初のボタンは1つのみ(次へ)、次の18は2つのボタン(次と前)、最後のフィールド2つのボタン(PreviousとSubmit)
"問題は1つの質問が選択され、20回繰り返されます":SQLクエリで20種類の質問があるかどうかを確認します。私はループと何かが間違っていると思う、多分同じ質問IDを取る、foreachを試してみてください。より正確な答えを得るためのコードをもっと与えることができれば、どうぞ。 –
タイトルに固有の問題を記述してください。 –
_ "すべてうまくいきます。問題は" _うまく動作しません。 :) –