title: How to display selected value from dropdown in wordpress
body: <p>I have state table having state_id and state_name. I am displaying it directly in template file like below..</p>
  
  <pre><code>  &lt;select name="state"  id="state"  class="select-submit2"&gt;
     &lt;option  value=""&gt;Select state&lt;/option&gt;
    &lt;?php 
      $result=$wpdb-&gt;get_results("select * from states");
      foreach($result as $row) {
          $state_id=$row-&gt;state_id;
          $state_name=$row-&gt;state_name;
          echo '&lt;option value='.$state_id.'&gt;'.$state_name.'&lt;/option&gt;';
      }
     ?&gt;     
  &lt;/select&gt; 
  </code></pre>
  
  <p>But when I want to edit that how do I show first selected state name.????</p>
  
  <p>Edit page url...
      whitecode.in/demo/plotsup_plot/new-property/?listing_edit=6795</p>
  
  <p>This is my function code in function.php file</p>
  
  <pre><code>   function getcity(){
        global $wpdb;
         if($_POST['state'])
              {
                  $id=$_POST['state'];
                  $property_id = $_GET['listing_edit']; 
                                       $district = get_post_meta($property_id, district, true);
                  $result=$wpdb-&gt;get_results("SELECT * FROM districts WHERE state_id='$id'");
                  //$wpdb-&gt;get_results($query);
                                foreach($result as $row) {
                                                               $city_name   = $row-&gt;district_name;
                               $city_id     = $row-&gt;district_id;
                          ?&gt;
       &lt;option value="&lt;?php echo $city_id; ?&gt;" &lt;?php if($district == $city_id){ echo 
    'selected="selected"';} ?&gt;&gt;&lt;?php echo $city_name; ?&gt;&lt;/option&gt;
    &lt;?php      
                                //echo '&lt;option value="'.$city_id.'"&gt;'.$city_name.'&lt;/option&gt;';
  
  
              }
     } 
     }
  </code></pre>