Jump to content

Help with ENUM


LukePVB

Recommended Posts

mySQL version:5.5.24

 

I need help with the column type ENUM. What I want to happen is for this column to get either yes or no values. I think ENUM is used specifically for this but i dont know how to set up the column for this to work. I tried to just select ENUM as the type and leave everything else blank but when I save it gives me the error "This is not a number". I have other columns, but im almost sure the error is coming from the ENUM column. Please help.

Link to comment
https://forums.phpfreaks.com/topic/274260-help-with-enum/
Share on other sites

Well, first of all you should NOT use an ENUM type if the values are Yes/No (i.e. TRUE/FALSE). Use a Boolean (or Tiny INT) type and store a 1 or 0. If you store a string such as "Yes" or "no" then you have to add additional logic to your code to process, such as

if($active=='yes')
{
   //Do something
}

 

instead, if you use 1 or 0 you can use those values directly because they are interpreted as logical TRUE and FALSE

if($active)
{
   //Do something
}

 

But, the reason you are getting the error is probably because you have some text type field (possibly the ENUM) for which you have not supplied a length.

Link to comment
https://forums.phpfreaks.com/topic/274260-help-with-enum/#findComment-1411314
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.