In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> ...will say if a field is of type "ENUM", but not its possible values 
> (including default). Does anyone know how I can fetch possible values 
> of a field type of ENUM?
> 
> Thanks.
> 
> ...Rene
> 
Try this little function which I use as an include file; there are 
possibly other and/or better ways to do it. Watch out for linewrap :-0

<?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;
 }
 ?>

-- 
Quod subigo farinam

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?

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

Reply via email to