View Full Version : Help with shorthand IF conditional please

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>

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...

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>

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


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.