gigantorTRON Posted September 18, 2007 Share Posted September 18, 2007 I'm creating a quiz type application that uses PHP to automatically load questions and their possible answers into an HTML page. The function I have that does this looks like this: switch($type) { //single line text box case "T": while ($out = mysql_fetch_row($result)) { $output .= $out[0] . ": <input type='text' name='" . $qid . $x . "'><br>"; $x++; } $x=0; break; //text area case "B": $output = "<form method='POST'>"; while ($out = mysql_fetch_row($result)) { $output .= $out[0] . ": <textarea name='firstname" . $x . "' cols=40 rows=6></textarea><br>"; $x++; } $x=0; break; //radio button case "R": while ($out = mysql_fetch_row($result)) { $output .= "<p><input type='radio' name='" . $qid . $x . "' value='" . $out[0] . "'>" . " " . $out[0] . "</p>"; $x++; } $x=0; break; case "C": while ($out = mysql_fetch_row($result)) { $output .= "<p><input type='checkbox' name='" . $qid . $x . "' value='" . $out[0] . "'>" . " " . $out[0] . "</p>"; $x++; } $x=0; break; //select (drop down) box case "S": $output = "<form method='POST'>"; while ($out = mysql_fetch_row($result)) { $output .= $out[0] . ": <input type='select' name='firstname" . $x . "'><br>"; $x++; } $x=0; break; default : } return $output; } This outputs the form elements with their names equal to question#choice i.e. 13a, 13b, etc. Another function then takes this data and saves it to a database table to track progress. Here's the problem I'm encountering... The html radio buttons are defined as a group by their 'name=' tag. Since each name tag is unique they are separate groups and a user could click multiple radio buttons rather than just one. Is there a way around this via css or something else? Or maybe a better way to approach this task? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/69786-solved-radio-button-form-help/ Share on other sites More sharing options...
freakstyle Posted September 18, 2007 Share Posted September 18, 2007 Hey there, i've run into this same issue myself. the way i worked around it, was to create a hierarchy of data and to dig down into as needed. in my db, here's how i set it up:: SurveyAnswerTypes id, name ( radio, textbox, textfield, checkbox ) SurveyAnswers id, survey_question_id, survey_answer_type_id, name, title, created, modified SurveyQuestions id, sort_ord, name, survey_id, created, modified SurveyResponses survey_id, survey_question_id, answer_value, ip, created Surveys: id, sort_ord, name, copy, status so then in the application logic, i loop over all the questions for this survey each question can have an answer, that answer would be one of the survey types the name of the answer (your radio, text, ....) would be the question_id so you can have more then one answer type for each question (radios and select boxes) ex of final result: http://www.soyconnection.com/newsletters/soy-connection/health-nutrition/survey.php?id=5 hope that helps a bit. good luck Quote Link to comment https://forums.phpfreaks.com/topic/69786-solved-radio-button-form-help/#findComment-350614 Share on other sites More sharing options...
gigantorTRON Posted September 18, 2007 Author Share Posted September 18, 2007 Nice! Thanks for the reply. I see that it may be more beneficial to define the answer type as radio/check box/etc. rather than define the question in that way. Did you happen to find any optional ways? Quote Link to comment https://forums.phpfreaks.com/topic/69786-solved-radio-button-form-help/#findComment-350619 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.