...

View Full Version : Help with shorthand IF conditional please



Bobafart
12-28-2007, 04:16 AM
I am trying to do a quick if conditional:



<select name="gender">
<option value="male" <?php ($row[gender] == "male" ? "selected" : "") ?> >male</option>
<option value="female" <?php ($row[gender] == "female" ? "selected" : "") ?> >female</option>
</select>



but it isn't working out.. when I select the users gender from the database and it is female it doesn't autoselect female

**"male" and "female" are exact string matches to the db -- there are no trailing spaces...

Mwnciau
12-28-2007, 04:19 AM
Try this:


<select name="gender">
<option value="male" <?php echo ($row['gender'] == "male") ? "selected" : ""; ?> >male</option>
<option value="female" <?php echo ($row['gender'] == "female") ? "selected" : ""; ?> >female</option>
</select>

Fou-Lu
12-28-2007, 05:19 AM
Ah, *slap slap slap*


'selected="selected"'

Sorry, thats the anal strict programmer in me :D
Its called the Ternary (triple involvment) operator btw, just in case you need to look it up on the php website in the future.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum