title: How to show selected value from database and show in dropdownlist using codeigniter and bootstrap
body: <p>When I select the all data of a product by it's product_id. and load product data in a form for an update. but here I cannot set selected drop-down list value in this case.</p>
  
  <p>here, is my view</p>
  
  <pre><code>      &lt;form action="&lt;?php //echo base_url().'admin_product/pro_update/'?&gt;" method="post" class="form-horizontal"&gt;
  
          &lt;div class="control-group"&gt;
            &lt;label class="control-label"&gt;Title :&lt;/label&gt;
            &lt;div class="controls"&gt;
              &lt;input type="text" class="span5 m-wrap" placeholder="Product title" name="title" value="&lt;?php echo $item[0]['p_title']?&gt;" /&gt;
  
             &lt;h6 style="color:red"&gt;&lt;?php echo form_error('title')?&gt;&lt;/h6&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="control-group"&gt;
            &lt;label class="control-label"&gt;Category :&lt;/label&gt;
            &lt;div class="controls"&gt;
              &lt;select name="cat" id="cat"&gt;
  
                &lt;option value=""&gt;--Select Category--&lt;/option&gt;
  
              &lt;?php foreach($cat as $c):?&gt;
  
      &lt;option value="&lt;?php echo $c-&gt;cat_id?&gt;"&gt;&lt;?php echo $c-&gt;cat_name;?&gt;//selected set value here&lt;/option&gt;
     &lt;?php endforeach;?&gt;
  
              &lt;/select&gt;
              &lt;h6 style="color:red"&gt;&lt;?php echo form_error('cat')?&gt;&lt;/h6&gt;
            &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>here is my controller code,</p>
  
  <pre><code> public function pro_edit($id)
  {
      $p['item']=$this-&gt;ap-&gt;product_update($id);
      $p['cat']=$this-&gt;ap-&gt;up_cat();
      $p['color']=$this-&gt;ap-&gt;up_color();  
     $this-&gt;load-&gt;view('layouts/header',$p);
     $this-&gt;load-&gt;view('admin/product_update',$p);
     $this-&gt;load-&gt;view('layouts/footer',$p);
  }
  </code></pre>
  
  <p>and model code,</p>
  
  <pre><code>public function product_update($id)
  {
      $this-&gt;db-&gt;select('p_title,p_description,p_category,p_stock_quantity,p_pprice,p_sprice,p_size_variant,cat_name,v_color,v_size,p_id');
      $this-&gt;db-&gt;from('tbl_product');
      $this-&gt;db-&gt;join('tbl_category','tbl_product.p_category=tbl_category.cat_id');
      $this-&gt;db-&gt;join('tbl_variant','tbl_product.p_color_variant=tbl_variant.v_id');
      $this-&gt;db-&gt;where('p_id',$id);
      $query=$this-&gt;db-&gt;get();
  
  
          return $query-&gt;result_array();
  
  }
  </code></pre>