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 2 of 2
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,452
    Thanks
    275
    Thanked 32 Times in 31 Posts

    echo select in loop with internal if

    This seems to work but just wanted to check its validity, or maybe a better way.

    while started
    PHP Code:

     
    echo "<option value='$val_name' if(selected='selected'){selected};>$val_val</option>"
    while end

    thanks

  • #2
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts
    I'm not quite sure how what ou posed would have worked.
    It would need to look something like this:

    PHP Code:
    echo "<option value='$val_name'" . ($selected == 'selected' 'selected=\'selected\'' '') . ">$val_val</option>"
    Check this out for more on shorthand if statements.
    http://davidwalsh.name/php-ternary-examples
    Need a way to drive traffic to your new site?
    ==> Check out HelpMyHits.com!

  • Users who have thanked Coastal Web for this post:

    durangod (02-20-2013)


  •  

    Posting Permissions

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