title: how to set select option if selected on submit in ci ,options value fetching from the database?
body: <p>i want to set select option if selected on submit in ci ,options value fetching from the database?
  i have tried it but it didn't work!
  can anyone tell me the solution?</p>
  
  <p>this is my controller</p>
  
  <pre><code> public function add(){
  
      $this-&gt;pageAction = 'Add';
  
      $error = array ();
  
      $finalData = array ();
  
      if($this-&gt;input-&gt;post('doAct') == strtolower($this-&gt;pageAction)){
  
  
  
          $this-&gt;form_validation-&gt;set_rules('country', 'Country Name', 'required');
          $this-&gt;form_validation-&gt;set_rules('city', 'City Name', 'required');
          $this-&gt;form_validation-&gt;set_rules('status', 'Status', 'required');
  
          if($this-&gt;form_validation-&gt;run() == FALSE){
  
              $finalData['error'] = "error";
          }else{
  
              $data = array (
               'c_id'=&gt;$this-&gt;input-&gt;post('country'),
               'name'=&gt;$this-&gt;input-&gt;post('city'),
               'active'=&gt;$this-&gt;input-&gt;post('status')
              );
  
  
  
              if($this-&gt;main_manager-&gt;insert($data, "city") == false){
  
                  $finalData['error'] = 'Cannot save data. Please try again.';
              }else{
  
                  $this-&gt;session-&gt;set_flashdata('msg', 'The data has been added successfully');
  
                  redirect(SITE_ADMIN_URL . "city_admin/index");
              }
          }
      }
      $finalData['country'] = $this-&gt;main_manager-&gt;select_all('country');
      $this-&gt;load-&gt;view('administrator/header');
  
      $this-&gt;load-&gt;view('administrator/add_city', $finalData);
  
      $this-&gt;load-&gt;view('administrator/footer');
  }
  </code></pre>
  
  <p>this is my view </p>
  
  <pre><code>&lt;form class="form-horizontal" name="" id="" enctype="multipart/form-data" method="post" action="&lt;?php echo SITE_ADMIN_URL;?&gt;city_admin/add"/&gt;
  
                      &lt;div class="control-group"&gt;
  
                          &lt;label class="control-label" for="form-field-1"&gt;Country Name&lt;/label&gt;
                          &lt;div class="controls"&gt;
                              &lt;select name="country"&gt;
                                  &lt;option value=""&gt;Please Select Country&lt;/option&gt;
                                  &lt;?php
                                  for($a = 0; $a &lt; count($country); $a++){
                                      ?&gt;
                                      &lt;option value="&lt;?php echo $country[$a]['id'];?&gt;"&gt;&lt;?php echo $country[$a]['name'];?&gt;&lt;/option&gt;
                                      &lt;?php
                                  }
                                  $select = "";
                                  if($country == "selected"){
                                      $country = $select;
                                      ?&gt;
                                      &lt;option value="&lt;?php echo $select[$a]['id'];?&gt;"&gt;&lt;?php echo $select[$a]['name'];?&gt;&lt;/option&gt;
                                  &lt;?php }
                                  ?&gt;
                              &lt;/select&gt;
                              &lt;!--&lt;input type="text" id="reason" name="country" value="&lt;?php // echo set_value('country');  ?&gt;" /&gt;--&gt;
  
                          &lt;/div&gt;
  
                      &lt;/div&gt;
  
                      &lt;div class="control-group"&gt;
  
                          &lt;label class="control-label" for="form-field-1"&gt;City&lt;/label&gt;
  
                          &lt;div class="controls"&gt;
  
                              &lt;input type="text" id="reason" name="city" value="&lt;?php echo set_value('city');?&gt;" /&gt;
  
                          &lt;/div&gt;
  
                      &lt;/div&gt;
                      &lt;div class="control-group"&gt;
  
                          &lt;label class="control-label" for="form-field-1"&gt;Status&lt;/label&gt;
  
                          &lt;div class="controls"&gt;
  
  
                              &lt;input type="radio" name="status" id="status" value="1" &lt;?php echo set_radio('status', '1');?&gt;&gt;
  
                              &lt;span class="lbl"&gt;&amp;nbsp;Active&lt;/span&gt;
  
                              &lt;input type="radio" name="status" id="status" value="0" &lt;?php echo set_radio('status', '0');?&gt;&gt;
  
                              &lt;span class="lbl"&gt;&amp;nbsp;Inactive&lt;/span&gt;
  
                          &lt;/div&gt;
  
                      &lt;/div&gt;
  
                      &lt;div class="space-4"&gt;&lt;/div&gt;
  
                      &lt;div class="form-actions"&gt;
  
                          &lt;input type="hidden" name="doAct" value="add"&gt;
  
                          &lt;button class="btn btn-info" type="submit" name="submit"&gt;
  
                              &lt;i class="icon-ok bigger-110"&gt;&lt;/i&gt;
  
                              Submit
  
                          &lt;/button&gt;
  
                          &amp;nbsp; &amp;nbsp; &amp;nbsp;
  
                          &lt;button class="btn" type="reset"&gt;
  
                              &lt;i class="icon-undo bigger-110"&gt;&lt;/i&gt;
  
                              Reset
  
                          &lt;/button&gt;
  
                      &lt;/div&gt;
  
                      &lt;/form&gt;
  </code></pre>