RE: [PHP-DB] Dealing with ENUM fields
| From: | Lisi | Date: | Mon, 02 Jun 2003 09:53:32 +0000 |
| Subject: | RE: [PHP-DB] Dealing with ENUM fields | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-28219@lists.php.net to get a copy of this message | ||
I am forwarding this useful function someone once sent to the list that I use often.
Hope this fits your needs.
-Lisi
-----Original Message----- From: Russ [mailto:russ@itomic.dns2go.com] Sent: Wednesday, June 26, 2002 7:47 PM To: NIPP, SCOTT V (SBCSI); php-db@lists.php.net Subject: RE: [PHP-DB] Populating a dropdown list with ENUM values... G'day Scott: I wrote this function to do just what you're atfer: You may need to mess with it for you're own needs - but go for your life! //----function: "enum_select()" - automatically generate an HTML select menu from a MySQL ENUM field //----1). takes a table name: '$table' //----2). a name for the menu '$name' //----3). a CSS class function enum_select($table,$name,$class) {$sql = "SHOW COLUMNS FROM $table"; $result = mysql_query($sql); $select = "<select name=\"$name\" class=\"$class\">\n\t"; while($myrow = mysql_fetch_row($result)){ $enum_field = substr($myrow[1],0,4); if($enum_field == "enum"){ global $enum_field; $enums = substr($myrow[1],5,-1); $enums = ereg_replace("'","",$enums); $enums = explode(",",$enums); foreach($enums as $val) { $select .= "<optionvalue=\"$val\">$val</option>\n\t";}//----end foreach }//----end if }//----end while $select .= "\r</select>"; return $select;}//----end function All the best. Russ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php