开发者

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?

开发者_JS百科

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;


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.


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

See the documentation for more details.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜