redbrad0 Posted July 15, 2008 Share Posted July 15, 2008 I know I can run SHOW CREATE TABLE TableName but it just outputs the following info CREATE TABLE `TableName` ( `Table_ID` int(11) unsigned NOT NULL auto_increment, `Table_Type` enum('Promoter','Media','Corporate') NOT NULL default 'Promoter', PRIMARY KEY (`Table_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 How can I just return the enum values in red? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 15, 2008 Share Posted July 15, 2008 Use DESCRIBE or SHOW COLUMNS Quote Link to comment Share on other sites More sharing options...
fenway Posted July 15, 2008 Share Posted July 15, 2008 MySQL 5.0 has the information_schema tables that will give you this information in a sql-usable way, too. Quote Link to comment Share on other sites More sharing options...
redbrad0 Posted July 15, 2008 Author Share Posted July 15, 2008 Thank you for the reply. For reference for anyone else that might find this thread, here is what I am using. function getEnumOptions($table, $field) { $finalResult = array(); if (strlen(trim($table)) < 1) return false; $query = "show columns from $table"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ if ($field != $row["Field"]) continue; //check if enum type if (ereg('enum.(.*).', $row['Type'], $match)) { $opts = explode(',', $match[1]); foreach ($opts as $item) $finalResult[] = substr($item, 1, strlen($item)-2); } else return false; } return $finalResult; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.