-1

Possible Duplicate:
Which MySQL Datatype to use for storing boolean values?

I have viewed many questions on this topic but I can not find an answer, I have a HTML form with 10 questions, each with a radio button for yes or no to be selected. when creating the table in the database (im using phpymadmin) what is the type I need to select for each question to store this yes no field? I am a novice use at this but all answers appreciated!

Community
  • 1
  • 1
Claddagh
  • 51
  • 2
  • 3
  • What is it about the answers that you've found that don't suit your needs? What options are your currently considering? – Dancrumb Nov 28 '12 at 14:05
  • the field could be anything, binary for 1 or 0 (yes or no) or even some kind of text field, varchar(3) or tiny text etc where you store the actual word, 'yes' or 'no'. – martincarlin87 Nov 28 '12 at 14:06
  • @martincarlin87 thank you, so if say i go for varchar option should i enter 'yes' and 'no' in values box? I will not be populating the table with data it will be coming from the form when it is submitted so i hope for the yes or no value to be read into the table depending on what the user has selected in the form. thank u – Claddagh Nov 28 '12 at 14:15
  • 1
    @Claddagh it's entirely up to you, there's no right or wrong answer, all you have to do is decide which approach you like best and use it consistently. Personally I think 1 and 0 might be best as it's immediately understandable and language independent – martincarlin87 Nov 28 '12 at 14:17

1 Answers1

3

This depends entirelly on the use case.

Some possibilities are:

  • Create a TINYINT(1) column and store 1 for yes and 0 for no;
  • Create a CHAR(1) column and store Y for yes and N for no;
  • Create a VARCHAR(3) CHARSET ascii COLLATE ascii_bin column and store 'yes' or 'no';

You are free to choose what fits your needs. And even these are only a few options. What is really important is picking one and sticking to it as a standard for this kind of data.

Also, you may not need to represent the no values at all in case your data doesn't have an option to be null. You can only set the yes values and let the default be treated as no.

Ricardo Souza
  • 16,030
  • 6
  • 37
  • 69