This is a discussion on Data Type for Checkbox and OptionButton within the MySQL Database forums, part of the Database Forums category; Hey I am building my 1st MySQL database and have 2 questions: 1) If I want to have a checkbox ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hey
I am building my 1st MySQL database and have 2 questions: 1) If I want to have a checkbox linked to a field in a table, what Data Type do I set for that field? 2) If I want to have 2 optionbuttons linked to 2 seperate fields in a table, what Data Type do I set for those fields? Thanks Todd |
|
|||
|
Todd Huttenstine wrote:
> Hey > > I am building my 1st MySQL database and have 2 questions: > > 1) If I want to have a checkbox linked to a field in a table, what Data Type > do I set for that field? TINYINT should be okey, use 0 for unchecked and 1 for checked (makes it easier in if-statements). > 2) If I want to have 2 optionbuttons linked to 2 seperate fields in a table, > what Data Type do I set for those fields? TINYINT should be okey, use 0 for unselected and 1 for selcted option (makes it easier in if-statements). -- //Aho |
|
|||
|
Todd Huttenstine wrote:
> Hey > > I am building my 1st MySQL database and have 2 questions: > > 1) If I want to have a checkbox linked to a field in a table, what Data Type > do I set for that field? > > 2) If I want to have 2 optionbuttons linked to 2 seperate fields in a table, > what Data Type do I set for those fields? > > > > Thanks > Todd > > Actually, it's irrelevant. You want to check/uncheck the box based on some condition. That is that condition? It might be true or false (1 or 0), in which case a tinyint would do. However, it may some completely different condition. For instance, if you're building a bulletin board system, you might want to allow or disallow the user access to one or more topics on the board. In this case you wouldn't even have a column for that checkbox. You would have a link table which has userid's and topicid's. If the userid/topicid pair is in the table, the checkbox would be checked. If it isn't in the table, the checkbox would be unchecked. IOW - don't get hung up on checkboxes. The display of the information should be is independent of the storage of the information. What you need to do is determine what the column needs to hold based on how it will be used in the rest of the program. After all, a column to just check/uncheck a box and do nothing else is worthless. Base the type of data for that column (or even the presence/absence of the column) on the logic in your code and what you need to store there. Then determine in your language of choice how to check/uncheck the box based on the actual data conditions. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |