CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   echo select in loop with internal if (http://www.codingforums.com/showthread.php?t=287953)

durangod 02-19-2013 11:58 PM

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

Coastal Web 02-20-2013 03:18 AM

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


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

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.