Re: get emum values

From: Date: Sun, 24 Feb 2002 19:25:56 +0000
Subject: Re: get emum values
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-86004@lists.php.net to get a copy of this message
I think I got this off the Zend site a year or so ago: // function mysql_fetch_enumerations($db_connection, $table_name, $column_name, $sorted="unsorted") { /* Author Thomas J. Swan Revision History 1.0 Creation of function 1.1 Added the ability to sort the array before returning it Parameters $db_connection an established mysql connection to the correct database $table_name name of Table containing the ENUMeration $column_name column whose possible values are to be listed $sorted sort array in "ascending","descending", or "unsorted" order Returns Array of valid values for an enumerated type Example $bob = mysql_fetch_enumerations($mysql_connection, "Event", "age_group"); while(list($key,$value) = each($bob)) { echo $value . " "; } echo "\n"; */ $table = addslashes($table); $field = addslashes($field); if ($result = mysql_query("SHOW COLUMNS FROM $table_name LIKE \"$column_name\"",$db_connection)) { $temp = mysql_fetch_array($result); if (strstr(strtoupper($temp['Type']),"ENUM")) { $str = StripSlashes(substr($temp['Type'], (strpos($temp['Type'],"(",0))+1, (strpos($temp['Type'],"\)",0)-1))); $tok = strtok($str,","); while ($tok) { $labels[] = substr($tok,(1),(strlen($tok) - 2)); $tok = strtok(","); } switch(strtolower($sorted)) { case "ascending" : sort($labels); break; case "descending" : rsort($labels); break; default : break; } return $labels; } else { echo ("Error not ENUM type\n"); } } else { echo ("Error querying database.\n"); echo mysql_errno( ).": ".mysql_error( )."\n"; } return false; } ----- Original Message ----- From: "Nick Wilson" <nick@explodingnet.com> Subject: [PHP] get emum values > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi all > Which php function can I use to get the emum values from a mysql db > table?

« previous php.general (#86004) next »