Checking the correct answer from the database by a checked radio button in PHP -
i creating online assessment. display questions randomly in 1 page only. have difficulty on how check right reply in database checked radio button. don't know , logic on how it.
this php codes displaying questions randomly,
$view_questions=mysql_query("select * questions order rand()");
this html codes php codes,
<form name="" method="post"> </br><h4># of questions</h4> <?php $i=1; while($row=mysql_fetch_array($view_questions)) { ?> <div class="view_question fsize"> <p align="justify"><?php echo $i;?>) <?php echo $row['question'];?></p> <div class="indent-question"> <input type="radio" value="1" id="" name="radio[<?php echo $row['question_no'];?>]"> <?php echo $row['answer_1'];?> </br> <input type="radio" value="2" id="" name="radio[<?php echo $row['question_no'];?>]"> <?php echo $row['answer_2'];?> </br> <input type="radio" value="3" id="" name="radio[<?php echo $row['question_no'];?>]"> <?php echo $row['answer_3'];?> </br> <input type="radio" value="4" id="" name="radio[<?php echo $row['question_no'];?>]"> <?php echo $row['answer_4'];?> </div> </div> <?php $i++; } ?> <center><button id='next<?php echo $i;?>' class='next btn btn-success' name="finish" type='submit'>finish</button></center> </form>
table name: questions
table fields: question_no, question, answer_1, answer_2, answer_3, answer_4, answer
it easy
store id of questions in value in radio button , checkbox value submitted checked , compare code after submitting form in next page , hope understand, trying say
php radio-button
No comments:
Post a Comment