Re: Displaying enum field values
| From: | Simon Robson | Date: | Tue, 23 May 2000 15:30:03 +0000 |
| Subject: | Re: Displaying enum field values | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-373@lists.php.net to get a copy of this message | ||
> If I wanted to display the field values for an ENUM type field in a
> form, how would I do this? Is there a tutorial somewhere showing how
> it is to be done?
>
> I've played around with SHOW, but clearly I'm doing something wrong by
> using this.
$sql = "show columns from TABLENAME like 'ENUM_COLUMN_NAME'";
is what the MySQL docs suggest, and it works, but it returns a string of
the form
enum('option1','option2',etc...)
Last time I had to do this I parsed the string out (example below) -- but
I'd love to hear of a more elegant way to do this.
$sql = "show columns from TABLENAME like 'ENUM_COLUMN_NAME'";
$conn = $this->CONN;
$result = mysql_query($sql,$conn);
$thisrow = mysql_fetch_array($result);
$valuestring = $thisrow[1];
$valuestring = ereg_replace("enum", "", $valuestring);
$valuestring = ereg_replace("\(", "", $valuestring);
$valuestring = ereg_replace("\)", "", $valuestring);
$valuestring = ereg_replace("\'", "", $valuestring);
$values = split(",", $valuestring);
which leaves $values as an array of the enum options. Long winded
though...
Simon