Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8395711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:22:11+00:00 2026-06-09T20:22:11+00:00

I will be honest here – I am pretty sure I am not approaching

  • 0

I will be honest here – I am pretty sure I am not approaching this from the best method
I have a survey software I am working on that allows the owner to build questions of different input types (text, checkbox, radio…) text was very easy it searched question table and found the field ans_type which is what contains text, checkbox, radio… and output

                switch ($rowq['ans_type']) {
            case "text":
                echo '<tr bgcolor="#DDDDDD"  align="left" valign="middle"><td width="30"> </td> <td width="350">'.$rowq['question'].'</td><td width="350"><input class="tb8" type="text" name="quest[]" value="'.$rowa['answer'].'" size="40"></td></tr>';
            break;

so as you can see – rowq contains my question information while rowa contains answer information.

my problem has arrisen at checkbox and radio where we may have multiple options currently my table is set up like this to allow up to 15 options for checkbox and radio

CREATE TABLE `question` (
 `sid` int(10) NOT NULL,
 `qid` double(10,1) NOT NULL,
 `question` varchar(500) NOT NULL,
 `ans_type` varchar(100) NOT NULL,
 `opt_one` varchar(200) DEFAULT NULL,
 `opt_two` varchar(200) DEFAULT NULL,
 `opt_three` varchar(200) DEFAULT NULL,
 `opt_four` varchar(200) DEFAULT NULL,
 `opt_five` varchar(200) DEFAULT NULL,
 `opt_six` varchar(200) DEFAULT NULL,
 `opt_seven` varchar(200) DEFAULT NULL,
 `opt_eight` varchar(200) DEFAULT NULL,
 `opt_nine` varchar(200) DEFAULT NULL,
 `opt_ten` varchar(200) DEFAULT NULL,
 `opt_eleven` varchar(200) DEFAULT NULL,
 `opt_twelve` varchar(200) DEFAULT NULL,
 `opt_thirteen` varchar(200) DEFAULT NULL,
 `opt_fourteen` varchar(200) DEFAULT NULL,
 `opt_fifteen` varchar(200) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

CREATE TABLE `answers` (
 `surveyid` int(10) NOT NULL,
 `question` double(10,1) NOT NULL,
 `answer` varchar(50000) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

so I need to determine how many options are available for any given question for these types first – I figured I could have it only add the checkbox if rowq[‘…’] != NULL on each of the opt_numbers this doesnt fix my second problem though – If this survey has been filled out already and the person is editing it I need the boxes they already selected to be checked (for checkboxes this might be all 15 it might be 1 for radio naturally it will only be one) rowa[‘answer’] contains my answers which will be separated by a “,” would it be easier to just add opt_one-fifteen to answers and have them contain an int 1 or 0 based off checked or not checked.

I honestly don’t know where to go from this any help is appreciated – including changing my database around if there is a better method.

case "radio":

break;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:22:13+00:00Added an answer on June 9, 2026 at 8:22 pm

    I have a system that looks a bit like yours. The way I go about it, is letting each question row have a field answerTypes and a field answers. answerTypes is an array that tells which answers can be given to the question.

    The system loops through the answerTypes array and fetches the appropriate answers that can be given from answers, e.g. if answerTypes is array(1,3), the answerTypes are radiobutton and text input.

    answers then has all the “specific” settings for the different answerTypes, such as the max length of text inputs, the different names for checkboxes and different values for radiobuttons.

    A little code snippet of how I do it:

      foreach($q->answerTypes AS $type) { 
              if($type == 1) { //radio buttons
                $ans = $q->answers['radioButton'];
                $return .= "<div class=\"radioButtonContainer\">";
                $return .= "<table><tbody>";
                foreach($ans AS $value=>$label) { 
                  $return .= "<tr><td><label for=\"radiobutton_{$value}\">{$label}</label> </td><td><input id=\"radiobutton_{$value}\" type=\"radio\" name=\"radioButton\" value=\"{$value}\"".(($_POST['radioButton'] == $value) ? ' checked' : '')."></td></tr>";
                }
                $return .= "</tbody></table>";
                if(!empty($errl['radioButton'])) { 
                  $return .= error($errl['radioButton'], 0, false);
                }
                $return .= "</div>";
              } elseif($type == 2) { //checkboxes
                $ans = $q->answers['checkbox'];
                $return .= "<div class=\"checkboxContainer\"><table><tbody>";
                foreach($ans['boxes'] AS $name=>$label) { 
                  $return .= "<tr><td><label for=\"checkbox_{$name}\">{$label}</label> </td><td><input id=\"checkbox_{$name}\" type=\"checkbox\" name=\"checkbox_{$name}\" value=\"1\"".(($_POST['checkbox_'.$name] == "1") ? ' checked' : '')."></td></tr>";
                }
                $return .= "</tbody></table>";
                if(!empty($errl['checkbox'])) { 
                  $return .= error($errl['checkbox'], 0, false);
                }
                $return .= "</div>";
              } elseif($type == 3) { //text input
                $ans = $q->answers['textInput'];
                $return .= "<div class=\"textInputContainer\">";
                if(!empty($ans['label'])) { 
                  $return .= "<div class=\"textInputLabel\"><label for=\"textInput\">{$ans['label']}</label></div>";
                }
                if(isset($errl['textarea'])) { 
                  $return .= error($errl['textarea'], 0, false);
                }
                $return .= "<input type=\"text\" onkeyup=\"countText($(this), $('#textInputChars'));\" id=\"textInput\" class=\"textInput\" name=\"textInput\" value=\"".htmlspecialchars($_POST['textInput'])."\"><br>
                <span class=\"smallText\"><span id=\"textInputChars\">".number_format(strlen($_POST['textInput']))."</span>/".number_format($ans['maxChars'])."</span></div>";
              } elseif($type == 4) { //textarea
                $ans = $q->answers['textarea'];
                $return .= "<div class=\"textareaContainer\">";
                if(!empty($ans['label'])) { 
                  $return .= "<div class=\"textareaLabel\"><label for=\"textarea\">{$ans['label']}</label></div>";
                }
                if(isset($errl['textarea'])) { 
                  $return .= error($errl['textarea'], 0, false);
                }
                $return .= "<textarea onkeyup=\"countText($(this), $('#textareaChars'));\" id=\"textarea\" class=\"textarea\" name=\"textarea\">".htmlspecialchars($_POST['textarea'])."</textarea><br>
                <span class=\"smallText\"><span id=\"textareaChars\">".number_format(strlen($_POST['textInput']))."</span>/".number_format($ans['maxChars'])."</span></div>";
              }
        }
    

    The data format is:

       [answerTypes] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )
    
    [answers] => Array
        (
            [radioButton] => Array
                (
                    [a] => Radio button 1 //radio button name => radio button label
                    [b] => Radio button 2
                    [c] => Radio button 3
                )
    
           [checkbox] => Array
               (
                   [atLeast] => 0 //the minimum number of checkboxes that have to be checked
                   [boxes] => Array
                       (
                           [a] => Checkbox 1 //checkbox name => checkbox label
                           [b] => Checkbox 2
                       )
    
               )
    
           [textInput] => Array
               (
                   [label] => Please fill in:
                   [maxChars] => 255
                   [required] => 1
               )
    
       )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure this is even possible to be honest, I am wondering
To be honest, I'm not sure if this is an issue with my code
I'm new to Java and have been asked to create an applet/servlet (not sure
To be honest, I actually have a solution for this, but Google search finds
I'm not sure if this is even within the scope of MySQL to be
to be honest- ive asked (a part of this question) here but now i
I am a little out of my depth here, I'll be honest. I am
I am trying to migrate the setup here at the office from SVN to
I am a bit new to LINQ, here is my problem. I have a
I hope this is okay to ask here as its more a request for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.