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? Link to comment https://forums.phpfreaks.com/topic/114886-solved-finding-enum-options-of-a-column-in-a-mysql-database/ Share on other sites More sharing options...
wildteen88 Posted July 15, 2008 Share Posted July 15, 2008 Use DESCRIBE or SHOW COLUMNS Link to comment https://forums.phpfreaks.com/topic/114886-solved-finding-enum-options-of-a-column-in-a-mysql-database/#findComment-590800 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. Link to comment https://forums.phpfreaks.com/topic/114886-solved-finding-enum-options-of-a-column-in-a-mysql-database/#findComment-590837 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; } Link to comment https://forums.phpfreaks.com/topic/114886-solved-finding-enum-options-of-a-column-in-a-mysql-database/#findComment-590859 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.