Return to Snippet

Revision: 2479
at February 27, 2007 11:33 by johnself


Initial Code
function enum($table, $field) {
	$result = @mysql_query("show columns from {$table} like \"$field\"");
	$result = @mysql_fetch_assoc($result);
	if($result["Type"])
	{
	preg_match("/(enum\((.*?)\))/", $result["Type"], $enumArray);
	$getEnumSet = explode("'", $enumArray["2"]);
	$getEnumSet = preg_replace("/,/", "", $getEnumSet);
	$enumFields = array();
	foreach($getEnumSet as $enumFieldValue)
	{
	if($enumFieldValue)
	{
	$enumFields[] = $enumFieldValue;
	}
	}
	return $enumFields;
	}
return false;
}

Initial URL

                                

Initial Description
Returns an array of values specified for an enumerated MySQL field

Initial Title
Get Enumerated Values for a MySQL Field

Initial Tags
mysql, php

Initial Language
PHP