Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Getting Values from a MySql ENUM Field

by Anonymous Monk
on Aug 15, 2002 at 22:35 UTC ( [id://190547]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello All,

I need to be able to extract all of the possible entry values for a MySql Field and print them into a HTML drop down feild.

The table is called temp and the field is called stage with the following options.

Stage` ENUM('registered','check','notify','complete','rejected') DEFAULT "registered" NOT NULL

I am sure there is a simple way of achieving this?

Thanks!!

Alistair

Replies are listed 'Best First'.
Re: Getting Values from a MySql ENUM Field
by greywolf (Priest) on Aug 16, 2002 at 00:20 UTC
    I found this in the MySQL documention:
    "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."

    I have used something like this in the past:
    A query like the one above will give you a string that has all the values in it. You can then split this string on commas into an array. You can then iterate the array and strip out the extra junk.

    It's kind of a nasty solution but it will work. I leave the details of how to accomplish this for your 'Fun Time'.

    mr greywolf
      in PHP it would be: preg_match_all( "|'(.+?)'|", $strType, $arrMatches ); Feel free to use the pattern.
Re: Getting Values from a MySql ENUM Field
by Mr. Muskrat (Canon) on Aug 16, 2002 at 00:08 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://190547]
Approved by Mr. Muskrat
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2024-04-25 04:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found