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
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
try this,
check $crew_rank_id == $crew_rank
store in variable and assign to it in <option>
tag
$selected = "";
if($crew_rank_id == $crew_rank)
{
$selected = "selected";
}
echo "<option value=".$crew_rank_id.".$selected.>".$crew_rank_table."</option>";
You are missing a double quotes in several places. The first one got the value and the "selected" to be one word, without spacing. The second before the closing of the option tag.
echo "<option value=".$crew_rank_id." ".(($crew_rank_id == $crew_rank) ? "selected" : "").">".$crew_rank_table."</option>";
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>";