473,653 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best way to save multiple checkboxes value in a database

107 New Member
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 18193
Atli
5,058 Recognized Expert Expert
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 New Member
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
13212
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: Hunter_69. Here is what the form looks like. I have the difficulty of inserting the multiple items selected by the user the first time he visits and uses the screen and then using an UPDATE when he visits later. Model | Original Price | Reduced Price...
9
3263
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 need to be visible at the same time so no dropdowns (combo boxes) and no scrolling lists (list boxes). I will use tabbed sheets with logically grouped categories (and their respective items).
6
14755
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' name='cbtype' value='3'> I'm wanting to re-display the same checkboxes, but if the user previously checked one of them then I want it automatically checked on
3
5146
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" type="checkbox" class="checkbox"'); if ($row == 1) { echo (' value="'.$row.'" checked />
1
2818
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 enter input. I need to take this user input and put it back into the database. What would be the best method to do this. I can't use a normal post because the name of the text box is the same for each table row. I've heard that posting the...
10
2227
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 an array of checkboxes, but my update loop is not working. Here is my code: /*---------This retrieves the records -------------*/ if($row_md) { do{ echo "<tr><td text align='right'>";
0
3104
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td colspan="2"><p>
11
15275
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 name=type..in the form of array..but on checking it the result in the database simply gives the world 'array'.i want multiple checkboxes to be checked and updated simultaneously.. and the query to insert the checkbox value has to be included along with...
3
2752
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, Modify. now i need to bind these check boxes from database table according to the four different fields in the table in which the value is 0 and 1. if the column value is 1 than the checkbox should be displayed checked otherwise no. i dont know how...
0
8370
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8704
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2707
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.