Vidya_tr Posted April 24, 2009 Share Posted April 24, 2009 I am developing a page for displaying a quiz. I have a page which displays a set of questions and three answers as choices for a question with a radio button beside each option to choose the answer. The radio buttons are generated dynamically while displaying the questions and their choices But when trying to choose the answer for each question on the page,i am able to check only a single radio button on the page.I am not able to check the radio buttons for each question. After choosing an option for the 1st question,when I try to choose for the second , the radio button for the 1st question is unchecked. the code for generating radio button is as follows.. $assign_questions=mysql_query("Select * from assign_questions where assignID=".$assignid.""); while($questions=mysql_fetch_array($assign_questions)) { echo $questions['question_number'].")"; echo $questions['question_text']."<br>"; $assign_answers=mysql_query("Select * from assign_answers where assignID=".$assignid." and question_number=".$questions['question_number'].""); $x=1; while($answers=mysql_fetch_array($assign_answers)) { echo' <input name="choice[]" type="radio" value="'.$answers['answer'].'" />'; echo $x++."."; echo $answers['answer']."<br>"; } } How can I avoid the problem of 'checked and unchecked' radio buttons??? Please help me... Link to comment https://forums.phpfreaks.com/topic/155486-solved-having-more-than-one-values-for-radio-buttons-on-a-page/ Share on other sites More sharing options...
Mark Baker Posted April 24, 2009 Share Posted April 24, 2009 echo' <input name="choice'.$questions['question_number'].'[]" type="radio" value="'.$answers['answer'].'" />'; Link to comment https://forums.phpfreaks.com/topic/155486-solved-having-more-than-one-values-for-radio-buttons-on-a-page/#findComment-818160 Share on other sites More sharing options...
Vidya_tr Posted April 24, 2009 Author Share Posted April 24, 2009 thank you... Its working.. I understood that it was a simple mistake in the logic. I need to have a unique array of radio buttons while looping. Link to comment https://forums.phpfreaks.com/topic/155486-solved-having-more-than-one-values-for-radio-buttons-on-a-page/#findComment-818165 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.