Re: Get all the enum values from a Mysql column?
| From: | (Tom) | Date: | Tue, 21 Nov 2000 19:04:10 +0000 |
| Subject: | Re: Get all the enum values from a Mysql column? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-4624@lists.php.net to get a copy of this message | ||
My little utility for just this
====================================
function getenumarray($table,$fieldname,$offset)
{
sqlinit();
$result=sqlexec("select * from $table LIMIT 1");
// $fieldname=mysql_field_name ($result, $offset);
$sql="DESCRIBE $table $fieldname";
$result=sqlexec($sql);
$row=mysql_fetch_row($result);
$pieces = explode ("'", $row[1]);
for($i=1;$i<count($pieces);$i++){
$enum_list[]=$pieces[$i];
$i++;
}
// $enum_list[]=sort($enum_list);
return $enum_list;
}
====================================
HTH
Tom Henry
John.Guynn@telescan.com (John Guynn) wrote in
<1B1034811F8BD311A8C300508B7294E8031C5983@EXCHANGE2>:
>Is there an easy way to get all the enum values from a column?
>
>For example I have an enum column with the values
>"Astro","Camaro","Firehawk","Neon" and I would like to
>pull those values
out
>to put in as <option>s in a html form with <select>.
>
>I've read the mysql maunal about pulling all the values from and enum
>column, "If you want to get all possible values for an ENUM column, you
>should use: SHOW COLUMNS FROM table_name LIKE enum_column_name and parse
the
>ENUM definition in the second column." For some reason I can't make heads
>or tails of this.
>
>Anyone?
>
>John Guynn
>
>