Bluehost.com Web Hosting $6.95

Data Type for Checkbox and OptionButton

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 ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-25-2007
Todd Huttenstine
 
Posts: n/a
Default Data Type for Checkbox and OptionButton

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


Reply With Quote
  #2 (permalink)  
Old 03-25-2007
J.O. Aho
 
Posts: n/a
Default Re: Data Type for Checkbox and OptionButton

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
Reply With Quote
  #3 (permalink)  
Old 03-25-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Data Type for Checkbox and OptionButton

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
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0