Re: mysql_field_type() ...

From: Date: Fri, 07 Nov 2003 12:33:49 +0000
Subject: Re: mysql_field_type() ...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-168832@lists.php.net to get a copy of this message
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?

« previous php.general (#168832) next »