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 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2012
    Location
    Somewhere over the Rainbow
    Posts
    96
    Thanks
    7
    Thanked 5 Times in 5 Posts

    dynamic values: radio buttons?

    Main question:
    Can I use radio buttons on a dynamic form and have the names filled in with the ENUM values of a database column?

    A group can only be one type of organization and one size within that organization. So instead of making a separate table to bring these things together, I made one column called "Organization Type" and set it to ENUM with 21 possibilities (7 types, 3 sizes each).

    I just started learning PHP a few weeks ago, so please forgive me if this is a question with an obviously simple answer.

    Sub question:
    If I can use radio buttons, where would I indicate the actual value to be put into the database record?

    My initial thoughts are:
    do an $orgtype = array( 'value 1', 'value 2', 'value 3'); (php)
    create a function that sets the orgtype (js)
    add "onClick settype()" to the radio button attributes (html)

    is that logical? would it work or am I missing something essential?

    ETA (trying to work it out while I hope for a response/feedback):

    So far:
    Code:
    //PHP
    $orgtype=$_POST['Organization Type'];
    
    //JS sets var based on ENUM values in database
    var orgtype=["Large Corporation","Medium Corporation", "Small Corporation"]
    I also see that I'd have to use onchange instead of onclick.

    Edit again: I found the answer to value question.
    Last edited by achira; 04-18-2012 at 09:21 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    There is a way to pull the actual enums available from a field with a query, but offhand I'm not sure what it is. You'll probably have to pull from information schema. I personally use lookup tables instead of enums as I find them much easier to work with when querying and updating (I'd rather insert than alter).
    The logic is identical whether you manually specify it, or if you allow it to be queried:
    - Get list of available options
    - Populate menu of options
    - Do some JS stuff if you want from those options
    - Submit that option
    - Either
    -- Check that the option is valid first then insert
    -- Insert and check if it failed to insert due to constraint / enum violation

  • Users who have thanked Fou-Lu for this post:

    achira (04-18-2012)

  • #3
    New Coder
    Join Date
    Mar 2012
    Location
    Somewhere over the Rainbow
    Posts
    96
    Thanks
    7
    Thanked 5 Times in 5 Posts
    I don't know what a lookup table is. I will go learn that. Thank you for the feedback.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Its just a table that typically has only one column, and it would be the same type and data used within the enum. It's bound on foreign key restraints that require the entries to come from that table, so random data cannot be entered in a related table.


  •  

    Posting Permissions

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