In article <[EMAIL PROTECTED]>, 
>       I am working on an application that has several different fields
> that are populated dropdown lists.  In every case, this data is simply data
> from a MySQL table column and works great.  I have run into a new difficulty
> though...  One field that I am wanting to populate in a dropdown list is an
> ENUM field.  I am trying to figure out how to do this.  I have seen a couple
> ideas in the newsgroups, but most are pretty complex and about a year or so
> old.  I am hoping for a simpler solution that may have been developed since
> these posts.  Thanks in advance.
> Scott Nipp
> Phone:  (214) 858-1289
> Web:  http:\\

Then you've possibly seen this one? I can't remember from whence I got it 
so can't properly attribute it. Watch the linewraps :-)
function mysql_fetch_enums( $link, $table_name, $field_name ){
/* Takes a connection link identifier, MySQL table name and field name for 
an enum type field
Returns an associative array containing the enum values as both key and 
value,ready to feed
to; or 0 on error */
        global $database;
   $mysql_datatype_field = 1;
   if (!$result = mysql_query ("SHOW COLUMNS FROM $table_name LIKE 
'$field_name'", $link ) ){
         echo mysql_error();
   } else {
     $mysql_column_data = mysql_fetch_row( $result );
     if ( !$enum_data= $mysql_column_data[$mysql_datatype_field] ){
     } else if ( !$buffer_array=explode("'", $enum_data) ){
       $output = 0;
     } else {
      $i = 0;
       reset ($buffer_array);
       while (list(, $value) = each ($buffer_array)) {
         if( $i % 2 ) $output[stripslashes($value)] = 
   return $output;

David Robley
Temporary Kiwi!

Quod subigo farinam

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to