tags:

views:

52

answers:

5

Hello,

I am using the MySQL table below. I would like to add a field called 'subcheck' that will be a yes/no value determined by the HTML form input TYPE = CHECKBOX. What "type" should I give this new field?

Thanks in advance,

John

`submission` (
  `submissionid` int(11) unsigned NOT NULL auto_increment,
  `loginid` int(11) NOT NULL,
  `title` varchar(1000) NOT NULL,
  `slug` varchar(1000) NOT NULL,
  `url` varchar(1000) NOT NULL,
  `displayurl` varchar(1000) NOT NULL,
  `datesubmitted` timestamp NOT NULL default CURRENT_TIMESTAMP,
  PRIMARY KEY  (`submissionid`)
)
+1  A: 

a boolean - 1 for yes, 0 for no.

(value of the checkbox will need to be 1 or 0 of course).

Much more portable than yes/no imo. efficient too

Ross
A: 

I would recommend a TINYINT(1) for this purpose. It stores either 1 or 0, to indicate yes or no. It takes very little space and is better supported across different SQL-engines than regular bool-types.

elusive
A: 

I would use numeric(1) not null default 0 wherein 0 indicates false and 1 indicates true.

BalusC
+1  A: 

You can use a TINYINT(1) (BOOL/BOOLEAN is just an alias for TINYINT(1)).

Another option is to store Y/N in a CHAR(1).

I would recommend TINYINT(1) as it would give you best portability options.

alexn
A: 

I personally prefer a enum or set data type in MySQL for this. It keeps the data legible.

CharlesLeaf