vendredi 22 mai 2020

What are my options for handling multiple choice checkbox data in database platforms?

When collecting data using an HTML form (or other technologies) I can use checkbox input fields sharing a name in order to give people the option to answer a question with multiple answers. I know there are two approaches to this.

Different input element names

  <input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
  <label for="vehicle1"> I have a bike</label><br>
  <input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
  <label for="vehicle2"> I have a car</label><br>
  <input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
  <label for="vehicle3"> I have a boat</label>

Same input element name

  <input type="checkbox" id="vehicle1" name="vehicles" value="Bike">
  <label for="vehicle1"> I have a bike</label><br>
  <input type="checkbox" id="vehicle2" name="vehicles" value="Car">
  <label for="vehicle2"> I have a car</label><br>
  <input type="checkbox" id="vehicle3" name="vehicles" value="Boat">
  <label for="vehicle3"> I have a boat</label>

I want to store the answers in a database of some kind so that I can present the answers back in different ways.

With the first option, I would store the data in separate fields. With the second option I would store the data in a single field, in some form of array. Are there other options in the HTML and the database?

What are the pros and cons of the different approaches?

I can easily find information about how to do either way in different server side languages and databases. I am more interested in why I would choose a particular technique, as once I have made that decision I can figure out how to apply it with any tools available (or choose a tool based on ability to apply the technique). I'm not even sure how to describe this problem to find answers on the internet.

Aucun commentaire:

Enregistrer un commentaire