ger enum values
Posted: Mon Oct 05, 2009 10:46 am
This function calculates all enum variables in a table
the structure of the shirt table is
Why the op array has two sub array with enum elements on each array ??
Code: Select all
include("database.php");
function getEnumValues($table, $field) {
$enum_array = array();
$query = 'SHOW COLUMNS FROM `' . $table . '` LIKE "' . $field . '"';
$result = mysql_query($query);
$row = mysql_fetch_row($result);
$data =$row[1];
preg_match_all('/\'(.*?)\'/', $data, $enum_array);
print_r($enum_array);
}
getEnumVAlues('shirt', 'style');
?>Code: Select all
mysql> show columns from shirt;
+-------+---------------------------------------------+------+-----+---------+--
--------------+
| Field | Type | Null | Key | Default | E
xtra |
+-------+---------------------------------------------+------+-----+---------+--
--------------+
| id | smallint(5) unsigned | NO | PRI | NULL | a
uto_increment |
| style | enum('t-shirt','polo','dress') | NO | | NULL |
|
| color | enum('red','blue','orange','white','black') | NO | | NULL |
|
| owner | smallint(5) unsigned | NO | | NULL |
|
+-------+---------------------------------------------+------+-----+---------+--
--------------+
4 rows in set (0.03 sec)Code: Select all
<body>
Array
(
[0] => Array
(
[0] => 't-shirt'
[1] => 'polo'
[2] => 'dress'
)
[1] => Array
(
[0] => t-shirt
[1] => polo
[2] => dress
)
)
</body>
</html>