MySQL: Storing checkbox values
Posted: Mon Oct 25, 2004 7:30 pm
I have a problem with storing information from checkboxes in a MySQL database. Let's take the example of a database with MP3 players. Every player has its own entry in the database. Now what I want is to record certain qualities that a player can possess. Every player can have up to ten qualities, like 'WMA support', 'Recording function', or 'FM Tuner'. To insert each product, I use a form on a php page and for the every possible quality I use a checkbox.
Now here's the problem. I have been searching for the best way to put these values in the database. Possible solutions:
1. Put the values in an array and store this in the database using SET
2. Create new columns for each possible quality. The values could be something like 'Y' and 'N' or '0' and '1'.
3. Create a new table that holds just the qualities. One column will hold the record ID from the original table, and another column will hold a number or whatever identifier for the quality.
Drawbacks for each solution:
1. From what I read, SET columns are not the most efficient ones, and will slow a search request.
2. Your table becomes huge. This can't be good for SELECT requests, right?
3. Linking the databases causes extra trouble. Also, every quality requires a new entry in the QUALITIES table. This is not efficient (I'd say), and again makes selecting records hard.
What do you think? Are these indeed possible solutions? Are there any other solutions?
I'd like to hear what you guys think!
Paul
Now here's the problem. I have been searching for the best way to put these values in the database. Possible solutions:
1. Put the values in an array and store this in the database using SET
2. Create new columns for each possible quality. The values could be something like 'Y' and 'N' or '0' and '1'.
3. Create a new table that holds just the qualities. One column will hold the record ID from the original table, and another column will hold a number or whatever identifier for the quality.
Drawbacks for each solution:
1. From what I read, SET columns are not the most efficient ones, and will slow a search request.
2. Your table becomes huge. This can't be good for SELECT requests, right?
3. Linking the databases causes extra trouble. Also, every quality requires a new entry in the QUALITIES table. This is not efficient (I'd say), and again makes selecting records hard.
What do you think? Are these indeed possible solutions? Are there any other solutions?
I'd like to hear what you guys think!
Paul