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: drop down menu

  1. #1
    Kal
    Kal is offline
    Regular Coder
    Join Date
    Dec 2005
    Posts
    309
    Thanks
    0
    Thanked 0 Times in 0 Posts

    drop down menu

    hi guys

    I have a database field called category. This can ewither be pork, beef, chicken. if i pull a record out and display it on the screen and the category is beef, how can i populate a category drop down with all 3 options but with beef selected?

    anyhelp would be great

    Thanks in advance

  • #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
    PHP Code:
    <select name="meatSelect">
    <option value="chicken" <?php echo ($databaseValue == "chicken" "selected" ""); ?> >Pork</option>
    <option value="pork" <?php echo ($databaseValue == "pork" "selected" ""); ?> >Pork</option>
    <option value="beef" <?php echo ($databaseValue == "beef" "selected" ""); ?> >Beef</option>
    </select>
    You will of course need to put your own variable names in there. This is basically just adding a PHP "if" statement to each <option> tag using the ternary syntax of (<condition> ? <true> : <false>), adding the keyword "selected" to the one option tag where the database value matches the option value.

  • #3
    Kal
    Kal is offline
    Regular Coder
    Join Date
    Dec 2005
    Posts
    309
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for that works perfectly.


  •  

    Posting Permissions

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