tags:

views:

28

answers:

3

How should my Mysql table data look like for a single checkbox that checks and see if the user has said yes if its clicked or no if its not?

Here is the checkbox.

<input type="checkbox" name="yes" id="yes" value="yes" />

I was wondering how would I add it to the following table.

CREATE TABLE IF NOT EXISTS `vote` (
`counter` int(8) NOT NULL default '0',
`value` int(8) NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
A: 

You'd probably want to use an ENUM or a BOOLEAN.

See the documentation for more details.

Dancrumb
+1  A: 

Use the TINYINT(1) datatype. I believe it is a synonym for BIT.

http://dev.mysql.com/doc/refman/4.1/en/numeric-types.html

http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html

Also, typically an unchecked checkbox will not submit anything, so you will need to check for null or nonexistent values.

jocull
A: 

Just make it an INT. Someday you might need to change it from a "Yes"/"No" to a "Yes"/"No"/"Maybe" and then you won't have to change the datamodel.

I view a checkbox as the same thing as a select-choice; just with only 2 choices (3 if you include "No choice yet made") so I treat it as such and stick with INT.

DancesWithBamboo