RE: [PHP-DB] Get all the enum values from a Mysql column?
| From: | John Guynn | Date: | Tue, 21 Nov 2000 17:55:18 +0000 |
| Subject: | RE: [PHP-DB] Get all the enum values from a Mysql column? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-4619@lists.php.net to get a copy of this message | ||
Thanks...works great.
I'm still not in full understanding of the regular expression stuff and
that's probably where I would have crashed and burned with this. Or I would
have kluged my way around it and ended up with REALLY UGLY code.
John Guynn
-----Original Message-----
From: Matt Williams [mailto:matt@yewlands.com]
Sent: Tuesday, November 21, 2000 10:51 AM
To: John Guynn; Php-Db (E-mail)
Subject: RE: [PHP-DB] Get all the enum values from a Mysql column?
>
> 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>.
try this
obviously you need to add the <from> and <select tags> :-)
$result = mysql_query("SHOW COLUMNS FROM table_name LIKE 'enum_column'");
while ($answer = mysql_fetch_array($result))
{
ereg( "('(.*)')", $answer[1], $temp );
$array = explode( "','", $temp[2] );
while (list ($key, $val) = each ($array))
{
echo "<option value=\"$val\">$val</option>\n";
}
}