Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-19-2013, 11:58 PM   PM User | #1
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,191
Thanks: 217
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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
durangod is offline   Reply With Quote
Old 02-20-2013, 03:18 AM   PM User | #2
Coastal Web
Regular Coder

 
Coastal Web's Avatar
 
Join Date: Oct 2004
Posts: 225
Thanks: 12
Thanked 3 Times in 3 Posts
Coastal Web is an unknown quantity at this point
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!
Coastal Web is offline   Reply With Quote
Users who have thanked Coastal Web for this post:
durangod (02-20-2013)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:10 AM.


Advertisement
Log in to turn off these ads.