Forum Moderators: coopster
I'm writing a script to select the current month within a select list.
What I've got so far - that works - is the following:
<select>
<option value="January" <?php echo ($month == '01'? "selected" : "");?>>January</option>
... (and so on)
</select>
Works beatifully. However, I've always wanted to shorten the syntax to get rid of the else part, like: <?php echo ($month == '01'? "selected");?> but it won't let me do it - throws parse errors.
I've looked for documentation on a shorter-shorthand conditional statement, but I can't find one.
Is it impossible to use this shorthand statement without including the "else" part?
Neophyte
you could use a straight if but I don't know if it is shorter
<?php if($month=='01') echo 'selected';?>
as opposed to
<?php echo ($month == '01'? "selected" : "");?>
though if you want even shorter then you could loop it. take a look at
Dynamic Date Selector [webmasterworld.com] msg 5 for what I mean