note 33571 deleted from function.mysql-field-type by didou

From: Date: Thu, 03 Jul 2003 08:10:21 +0000
Subject: note 33571 deleted from function.mysql-field-type by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-51400@lists.php.net to get a copy of this message
Note Submitter: e@eikimartinson.c0m ---- Here is some code expanding on the comment by krang. It parses the allowed values out of an enum type, and puts these in an array. Useful for generating select boxes for search pages and the like - the behaviour is slightly different than doing "SELECT DISTINCT" as this method will provide all the possibilities, not merely what happens to be in the table at the time. $result = mysql_query("SHOW FIELDS FROM database_name.table_name LIKE 'enum_column_name'"); $row = mysql_fetch_array($result); if(preg_match("/^enum\((.*)\)$/", $row['Type'], $matches)) { $values = split(",", preg_replace("/'/", "", $matches[1])); }

« previous php.notes (#51400) next »