In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
>       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
> E-mail:  [EMAIL PROTECTED]
> Web:  http:\\ldsa.sbcld.sbc.com

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 :-)
 
<?php
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 dropdown.inc; or 0 on error */
        global $database;
        mysql_select_db($database);
   $mysql_datatype_field = 1;
   if (!$result = mysql_query ("SHOW COLUMNS FROM $table_name LIKE 
'$field_name'", $link ) ){
     $output=0;
                 
         echo mysql_error();
   } else {
     $mysql_column_data = mysql_fetch_row( $result );
     if ( !$enum_data= $mysql_column_data[$mysql_datatype_field] ){
       $output=0;
     } 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)] = 
stripslashes($value);
         ++$i;
       }
     }
   }
   return $output;
 }
 ?>

Cheers
-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

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

Reply via email to