note 33571 added to function.mysql-field-type
| From: | e at eikimartinson dot c0m | Date: | Tue, 01 Jul 2003 01:22:00 +0000 |
| Subject: | note 33571 added to function.mysql-field-type | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51245@lists.php.net to get a copy of this message | ||
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]));
}
----
Manual Page -- http://www.php.net/manual/en/function.mysql-field-type.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33571
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33571&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33571&report=yes