Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Enum

  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts

    Enum

    If you have an enum field, is it possible to get a list of all the values?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The manual suggests:

    If you want to determine all possible values for an ENUM column, use SHOW COLUMNS FROM tbl_name LIKE enum_col and parse the ENUM definition in the Type column of the output.

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    For anyone else wondering - I also found in the comments this nifty little function
    PHP Code:
    $result mysql_query("SHOW COLUMNS FROM <table>");

    // Makes arrays out of all ENUM type fields.
    // Uses the field names as array names and skips non-ENUM fields
    while( $row mysql_fetch_row($result) )
    {
       
    extract($row);
       if (
    substr($Type04) != 'enum') continue;

       
    $Type str_replace('enum''array'$Type);
       
    // Make array
       
    eval("$" $Field " = " $Type);



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •