ger enum values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

ger enum values

Post by lipun4u »

This function calculates all enum variables in a table

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');
?>
the structure of the shirt table is

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)
Why the op array has two sub array with enum elements on each array ??

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>
 
Post Reply