Puedes usar la función mysql_fethc_field()
http://www.php.net/mysql_fetch_field
Un ejemplo completo:
Cita: kflam at awc dot net dot au
19-Jun-2002 06:56
#Input: the table name and the enum field
#Output: an array that stores all options of the enum field or
#false if the input field is not an enum
Código PHP:
function getEnumOptions($table, $field) {
$finalResult = array();
if (strlen(trim($table)) < 1) return false;
$query = "show columns from $table";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)){
if ($field != $row["Field"]) continue;
//check if enum type
if (ereg('enum.(.*).', $row['Type'], $match)) {
$opts = explode(',', $match[1]);
foreach ($opts as $item)
$finalResult[] = substr($item, 1, strlen($item)-2);
}
else
return false;
}
return $finalResult;
}
The function could be handy when making a selection option without typing all the options items respectively.
*Extraido de los comentarios de los usuarios de dicha función del manual oficial de PHP.
Su uso:
Código PHP:
$array_opciones=getEnumOptions('tabla_nombre', 'nombre_campo_emum');
foreach ($array_opciones as $opcion){
echo $opcion."<br>";
}
Un saludo,