mySQL
mySQL

Reputation: 21

MySQL table data question?

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;

Upvotes: 2

Views: 64

Answers (3)

DancesWithBamboo
DancesWithBamboo

Reputation: 4156

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.

Upvotes: 0

jocull
jocull

Reputation: 21115

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.

Upvotes: 1

Dancrumb
Dancrumb

Reputation: 27539

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

See the documentation for more details.

Upvotes: 0

Related Questions