Adrian Pascua Adrian Pascua - 1 year ago 53
PHP Question

Am I using the ternary operator?

Here is my code:

echo "<option value=".$crew_rank_id.".(($crew_rank_id == $crew_rank) ? "selected" : "").>".$crew_rank_table."</option>";


what im trying to do is echo out the selected value from the database in
echo

Answer Source

Your mixing PHP statements and PHP variables in the string and have some missing quotes and HTML-tags.

This should work:

echo "<option value='{$crew_rank_id}' ". (($crew_rank_id == $crew_rank) ? "selected" : "") . ">{$crew_rank_table}</option>";