title: Display value for dropdown populated from database (SQL Server)
body: <p>I am trying to display the saved value for a dynamic dropdown that is populated from a database. My code is as below : </p>
  
  <pre><code>&lt;?PHP
  $server = "xxx";
  $options = array(  "UID" =&gt; "xxx",  "PWD" =&gt; "xxx",  "Database" =&gt; "xxx");
  $conn = sqlsrv_connect($server, $options);
  if ($conn === false) die("&lt;pre&gt;".print_r(sqlsrv_errors(), true));
  echo " ";
  
  $myquery="SELECT Department FROM Change_Details WHERE id='2137'";   
  $fetched=sqlsrv_query($conn,$myquery) ; 
  if( $fetched === false ) { die( print_r( sqlsrv_errors(), true ));}
      while($res=sqlsrv_fetch_array($fetched,SQLSRV_FETCH_ASSOC))
      {
          $Department=$res['Department'];
      }
   ?&gt;
  
  &lt;div class="container"&gt; &lt;!-- Department --&gt;
      &lt;div class="form-inline clearfix"&gt;
          &lt;label class="col-md-5"&gt;Department initiating the Request&lt;/label&gt;
              &lt;label name="Department"&gt;&lt;/label&gt;
                  &lt;div class="col-md-5"&gt;
                              &lt;?PHP
                              echo "&lt;select name= 'Department' class='form-control selectpicker' onChange='getState(this.value)' Required&gt;";
                              echo '&lt;option value="$Department"&gt;'.'--Please Select Department--'.'&lt;/option&gt;';
                              $sql = "SELECT ID,Name FROM Departments";
                              $query = sqlsrv_query($conn,$sql);
                              $query_display = sqlsrv_query($conn,$sql);
                              while($row=sqlsrv_fetch_array($query_display,SQLSRV_FETCH_ASSOC)){
                              echo "&lt;option value='". $row['Name']."'&gt;".$row['Name']. '&lt;/option&gt;';
                              }
                              echo "&lt;/select&gt;";
                          ?&gt;
                  &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;&lt;br/&gt;
  </code></pre>
  
  <p>What is working : The dropdown is being populated perfectly, and the value is also saved into the database.</p>
  
  <p>What I need : Want to display the saved value from the database and the dropdown as well for the user to edit that field again. Appreciate any help :)</p>