PHP NOTES 24 NOTE 33571 ADDED TO FUNCTION MYSQL FIELD TYPE
Date: 1 Jul 2003 01:22:00 -0000

Subject: note 33571 added to function.mysql-field-type
From: e@no-spam

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


Date: 3 Jul 2003 08:10:21 -0000

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








From: didou@no-spam
Note Submitter: e@no-spam
----

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]));
}