Ver Mensaje Individual
  #3 (permalink)  
Antiguo 30/12/2004, 05:28
Cluster
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 4 meses
Puntos: 129
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($item1strlen($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,

Última edición por Cluster; 30/12/2004 a las 05:31