-5

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

Adi
  • 72
  • 1
  • 2
  • 16

3 Answers3

0

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>";
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Dave
  • 3,073
  • 7
  • 20
  • 33
0

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>";
iliaz
  • 395
  • 2
  • 10
0

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>";
M. Eriksson
  • 13,450
  • 4
  • 29
  • 40