Thanks to everyone who responded.  I have found a function that
fills the role perfectly.

-----Original Message-----
From: Russ [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 26, 2002 7:47 PM
To: NIPP, SCOTT V (SBCSI); [EMAIL PROTECTED]
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 .= "<option
value=\"$val\">$val</option>\n\t";
                                        }//----end foreach
                                }//----end if
                        }//----end while
                $select .= "\r</select>";
                return $select;
}//----end function


All the best.
Russ

-----Original Message-----
From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 27, 2002 3:38 AM
To: '[EMAIL PROTECTED]'
Subject: [PHP-DB] Populating a dropdown list with ENUM values...


        I am working on an application that has several different fields
that are populated dropdown lists.  In every case, this data is simply
data
from a MySQL table column and works great.  I have run into a new
difficulty
though...  One field that I am wanting to populate in a dropdown list is
an
ENUM field.  I am trying to figure out how to do this.  I have seen a
couple
ideas in the newsgroups, but most are pretty complex and about a year or
so
old.  I am hoping for a simpler solution that may have been developed
since
these posts.  Thanks in advance.

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to