Question: found this from [one of the answers from this question](https://stackoverflow.com/questions/33117718/get-the-value-from-database-in-selecte-tag-html-php-mysql)

And I would like to ask, is there something wrong with this?
I've var\_dump the column course right it displays BSIT.
But I couldn't get if the user is BSIT it goes to the BSCS selected option.

```
<select class="form-control" name="course">
    <?php
        if ($row['course'] == 'BSIT') {

        echo "<option selected>BSIT</option>";
        echo "<option>BSCS</option>";

        } else {
        echo "<option selected>BSCS</option>";
        echo "<option>BSIT</option>";
    }
    ?>
</select>    

```

Answer: 
just use this code

```
<?php
// $row['course'] = 'BSCS';
 ?>
<select class="form-control" name="course" >
 <option  <?php if($row['course'] == 'BSIT' ) { echo "selected='selected'"; }?>  >BSIT</option>
<option <?php if($row['course'] == 'BSCS' ) { echo "selected='selected'"; }?> >BSCS</option>
</select>

```

no need to check condition and change $row['course'] = 'BSIT'; for you test
You have missed the `select` tag here. Also assign value to the option to retrieve it back

```
echo "<select>";
        if ($row['course'] == 'BSIT') {

            echo "<option selected>BSIT</option>";
            echo "<option>BSCS</option>";

        } else {
            echo "<option selected>BSCS</option>";
            echo "<option>BSIT</option>";
    }
    echo "</select>";

```

Instead of using echo each time the best practice is to store the content in a variable and echo it after 

```
<?php
    $msg="";
//retrieve the $row['course'] from the DB. Fetch the result and store 
        if ($row['course'] == 'BSIT') {

            $msg.= "<option selected>BSIT</option>";
            $msg.= "<option>BSCS</option>";

        } else {
            $msg.= "<option selected>BSCS</option>";
            $msg.= "<option>BSIT</option>";
    }

?>
<select class="form-control" name="course" >
<?php echo $msg;?>
</select>

```