This is a discussion on mysql_field_type() ... within the PHP General forums, part of the PHP Programming Forums category; ....will say if a field is of type "ENUM", but not its possible values (including default). Does anyone ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
"René fournier" <m5@renefournier.com> wrote in message
news:D9DBDF2D-0E2F-11D8-A33D-0003931DAC94@renefournier.com... > ...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? desc $tbl_name; You'll have to parse it, but it will give you the list of available values. > > Thanks. > > ...Rene |
|
|||
|
In article <D9DBDF2D-0E2F-11D8-A33D-0003931DAC94@renefournier.com>,
m5@renefournier.com 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? |