I need to set the items in a PHP drop down menu based on a number of conditions.
Here's my code:
<select class="span3" id="filter-source">
<option selected="selected">Select source</option>
<?php
if (($_SESSION['val1']==="value")||($_SESSION['id']==5)) {
echo '<option';
if ($val2 == "Something"){
echo 'selected="selected"';
}
echo'Something</option>';
}
?>
</select>
So what I'm doing is displaying the option in the select dropdown only if one the two conditions for the session variables is true. Once 'Something' is selected then $val2 is set as something and on refreshing the page it is displayed as the selected option in the select drop down menu.
This does not result in an server error but the option does not show up at all even if the conditions for the session variables are satisfied.
What am I doing wrong and what is the correct way to do this?