At 14:40 -0700 7/25/02, Mark Middleton wrote:
>Hi there,
>
>I've got a Form I'm building, and would like the drop down boxes to contain
>the values for one of the fields of type "enum" (not from the actual records
>in the DB, but the definition of the enum field in MySQL)
>
>For example:  A field called "userlevel" with enum types "admin" and
>"visitor".
>
>I would like to run a query to get the values "admin" and "visitor" (and any
>other enum value types) to use in a drop down list on a form.
>
>Here's what I've found so far (seems pretty bulky):
>
>If you run a query of "SHOW COLUMNS FROM tablename" it gives the returned
>value of "enum('admin', 'visitor')" in the second column (column called
>"type")
>
>A snippet of code we found in PHPMyAdmin gives this little routine:
>
>         $enum        = str_replace('enum(', '', $row_table_def['Type']);
>         $enum        = ereg_replace('\\)$', '', $enum);
>         $enum        = explode('\',\'', substr($enum, 1, -1));
>         $enum_cnt    = count($enum);
>
>Which apparantly takes the result from the "SHOW COLUMNS..." query and
>strips out the values.
>
>Is this the easiest way to do this using PHP and MySQL?

I don't know if it's strictly the easiest, but all methods of getting
ENUM values rely on parsing apart the SHOW COLUMNS information somehow.
If you're asking whether there's some other way than that, there isn't.

>
>Any help is greatly appreciated - thank you!
>
>Mark Middleton
>Whirled Web


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to