Selected value in a list
<p>I'm trying to show the selected value in the list if it's found matching. It's successfully populated but the selected value code does not run.</p>

<pre><code>Code:
$StaffName = 'Jimmy Chan';
&lt;select name="Staff" id="Staff"&gt;&lt;?php
$data = array();
$data[0] = '';
echo "&lt;option value='" . $data[0] . "'&gt;" . $data[0] . "&lt;/option&gt;";
$result= $DB-&gt;query('select No, FirstName, LastName from Staff');
foreach ($result as $data)
{
    $SNo = $data['No'];
    $SFN = $data['FirstName'];
    $SLN = $data['LastName'];
    $SName = $SFN.' '.$SLN;         

    if($SName == $StaffName)
    {
        echo "&lt;option value='".$Sno."' selected = \"selected\"&gt;".$Sname."&lt;/option&gt;\n";
    }
    else
    {
    echo "&lt;option value='" .$SNo. "'&gt;" . $SName . " &lt;/option&gt;";
    }

}                 
?&gt;
        &lt;/select&gt;
</code></pre>

<p>The second else statement do run but not the if statement. I have already put the "selected" inside. Kindly advise.</p>
