View Full Version : Enum

09-09-2006, 04:42 PM
If you have an enum field, is it possible to get a list of all the values?

09-09-2006, 07:04 PM
The manual suggests:

If you want to determine all possible values for an ENUM column, use SHOW COLUMNS FROM tbl_name LIKE enum_col and parse the ENUM definition in the Type column of the output.

09-09-2006, 07:07 PM
For anyone else wondering - I also found in the comments this nifty little function

$result = mysql_query("SHOW COLUMNS FROM <table>");

// Makes arrays out of all ENUM type fields.
// Uses the field names as array names and skips non-ENUM fields
while( $row = mysql_fetch_row($result) )
if (substr($Type, 0, 4) != 'enum') continue;

$Type = str_replace('enum', 'array', $Type);
// Make array
eval("$" . $Field . " = " . $Type);