473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

best way to save multiple checkboxes value in a database

107 100+
hey experts, please advise me what is the best way to save multiple checkboxes value in a database. I have 6 checkboxes and i came across storing the values in a single column of a table which i dont want to implement as the checkbox values may be used for search purpose in latter stage. Apart from that i also came across creating individual columns for each checkbox which i feel would really make my table large. Is there any other way that i can do the same in a professional way?
Feb 18 '09 #1
3 18139
Atli
5,058 Expert 4TB
Hi.

That would depend on your data. But you are quite right not to want to store them all in a single column. That would violate the first normal form.

If the number of checkboxes is not going to change, and each row of the table should only contain a single value for each of them, the most efficient method would probably be to simply add a column for each of them.
Expand|Select|Wrap|Line Numbers
  1. +-----+-------+-------+-------+
  2. | ID  | Box1  | Box2  | Box3  |
  3. +-----+-------+-------+-------+
  4. | 1   | TRUE  | FALSE | NULL  |
  5. | 2   | TRUE  | NULL  | FALSE |
  6. | 3   | NULL  | TRUE  | FALSE |
  7. +-----+-------+-------+-------+
(If you feel this would clutter your original table, you could also simply put these columns in a separate table and set up a 1:N relationship between them)

But, if the checkboxes are dynamic, and you want to be able to add/remove boxes from the list, you may want to set up a N:M relationship, where each row in your table could have a value for each checkbox.
This would require a separate table to store the ceckboxes, and an intermediary table to store the values each row in table A has for each checkbox.
Like:
Expand|Select|Wrap|Line Numbers
  1. /* Your table */
  2. +-----+
  3. | AID | 
  4. +-----+ 
  5. | 1   |
  6. | 2   |
  7. | 3   | 
  8. +-----+
  9.  
  10. /* The table for the boxes */
  11. +-------+-------+
  12. | BoxID | Label |
  13. +-------+-------+
  14. | 1     | Box1  |
  15. | 2     | Box2  |
  16. | 3     | Box3  |
  17. +-------+-------+
  18.  
  19. /* The intermediary table 
  20.  * linking them together */
  21. +-----+-------+-------+
  22. | AID | BoxID | Value |
  23. +-----+-------+-------+
  24. | 1   | 1     | TRUE  |
  25. | 1   | 2     | FALSE |
  26. | 2   | 1     | TRUE  |
  27. | 2   | 3     | FALSE |
  28. | 3   | 2     | TRUE  |
  29. | 3   | 3     | FALSE |
  30. +-----+-------+-------+
See what I mean?
Feb 18 '09 #2
raamay
107 100+
i m sure the 2nd option is gonna work for me because my checkboxes is not dynamic. Anyway thank you man!
Feb 19 '09 #3
Greatest response ever, thank you Atli
Nov 22 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
9
by: Frances | last post by:
Hi All, * PREMISE * I'm creating an Access form with 150 items subdivided into 20 categories. Multiple categories (and items) can be selected so my user wants checkboxes. All of the options...
6
by: jeffsnox | last post by:
Hi, I have multiple checkboxes on the same form as follows: <input type='checkbox' name='cbtype' value='1'> <input type='checkbox' name='cbtype' value='2'> <input type='checkbox'...
3
by: mountain.dog | last post by:
I have a query that shows a list of options that a user can toggle on or off using a checkbox. query... form... while($row = mysql_fetch_array($result))... <input name="menu_show_attribute"...
1
by: Muchach | last post by:
Hello, Ok so what I've got going on is a form that is populated by pulling info from database then using php do{} to create elements in form. I have a text box in each table row for the user to...
10
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
3
by: santoshjsh | last post by:
hello everyone, i have a gridview in which i have multiple checkboxes in a single column. means for every row in the gridview i have four checkboxes in one column e.g Add, Delete, Print,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.