2017-04-23 19 views
0
question{ 
question_id, 
option1, 
option2, 
option3, 
option4, 
answer 
} 

exam_paper{ 
exam_paper_id, 
exam_paper_name 
} 

exam_question_list{ 
id, 
exam_paper_id, 
question_id 
} 

applicant_do_exam{ 
applicant_do_exam_id, 
exam_paper_id, 
question_id, 
app_answer 
} 

I want to display the questions in exam_paper_id=1 

$query="SELECT * FROM exam_question_list e LEFT JOIN question q ON e.question_id=q.question_id where exam_paper_id='$exid'"; 
$result=mysqli_query($dbcon,$query); 

<form action="exampaper_result.php?id=<?php echo $exid; ?>&stime=<?php echo $stime?>" method="post"> 

<table> 
<!--question_1--> 
<?php 

     $i=1; 
     while($row = mysqli_fetch_array($result)){ 

?> 
    <tr> 


    <tr id="exquestion" data-label="QuestionID"><td><input type="hidden" name="question_id" value="<?php echo $row['question_id']; ?>" /></td></tr> 
    <tr id="exquestion" data-label="Question"><td><span><?php echo $i++; ?>)&nbsp;&nbsp;</span><?php echo $row['question']; ?></td></tr> 
     <tr data-label="Question"><td><input id="exoption" type="radio" name="app_answer" value="1"/><?php echo $row['option1']; ?></td></tr> 
     <tr data-label="Question"><td><input id="exoption" type="radio" name="app_answer" value="2"/><?php echo $row['option2']; ?></td></tr> 
     <tr data-label="Question"><td><input id="exoption" type="radio" name="app_answer" value="3"/><?php echo $row['option3']; ?></td></tr> 
     <tr data-label="Question"><td><input id="exoption" type="radio" name="app_answer" value="4"/><?php echo $row['option4']; ?></td></tr> 

</tr> 


<?php 
    } 
    ?> 

    </table> 

    <input name="submit" type="submit" id="Submit" value="Submit"/> 

    </form> 

ここで質問とそのオプションを正しく取得できます。 各質問でラジオボタン(回答)を選択することはできません。 すべての質問に対してラジオボタンを1つだけ選択するためにページ全体が表示されます。ラジオボタンが正しく動作しない理由

私のエラーは何ですか?

+0

ラジオボタンのIDはすべて同じです。そうではありません。彼らはすべて同じ名前を持つ必要がありますが、すべてのコントロールには一意のIDが必要です。 – Bindrid

+0

これを行う方法は? –

+0

質問1ラジオボタン(回答)を選択すると、質問2ラジオボタン(回答)をクリックすると質問1ラジオボタンが選択解除され、質問2ラジオボタンが選択されます –

答えて

0

各セクションの名前をそれぞれのコンテキスト内で選択できるように分割する必要があります。例えばname="app_answer[<?php echo $i; ?>]"のように$_POST['app_answer'] = array()を提供します。

ので、同様に:あなたは、あなたの希望の形式に$g/question_idキーを解析できるようにする必要があるだろう提出

<?php 
$answers = (array) $_POST['app_answer']; 
//type-casted to ensure empty value is still a blank array 
foreach ($answers as $question_id => $answer) { 
    echo 'Answer to Question - ' . $question_id . ': ' . $answer . '<br/>'; 
} 
exit; 

while ($row = mysqli_fetch_array($result)) { 
    $g = $row['question_id']; 
?> 
     <tr id="exquestion" data-label="Question"><td><span><?php echo $i++; ?>)&nbsp;&nbsp;</span><?php echo $row['question']; ?></td></tr> 
     <tr data-label="Question"><td><input id="exoption" type="radio" name="app_answer[<?php echo $g; ?>]" value="1"/><?php echo $row['option1']; ?></td></tr> 
     <tr data-label="Question"><td><input id="exoption" type="radio" name="app_answer[<?php echo $g; ?>]" value="2"/><?php echo $row['option2']; ?></td></tr> 
     <tr data-label="Question"><td><input id="exoption" type="radio" name="app_answer[<?php echo $g; ?>]" value="3"/><?php echo $row['option3']; ?></td></tr> 
     <tr data-label="Question"><td><input id="exoption" type="radio" name="app_answer[<?php echo $g; ?>]" value="4"/><?php echo $row['option4']; ?></td></tr> 
<?php } /*end while*/ ?> 

結果。

関連する問題