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" <[EMAIL PROTECTED]>
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?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php