Welcome Guest, Not a member yet? Register   Sign In
2 column table to form_dropdown array
#2

[eluser]malzahar[/eluser]
Something like this may work.

In your model:
Code:
function get_names() {
   $names= array();
   $query = $this->db->get('table_name');
   if($query->num_rows() > 0) {
      foreach($query->result_array() as $name) {
         $names[] = $name;
      }
   }
   $query->free_result();
   return $names;
}

Your controller:
Code:
$this->load->model('model_name');
$data['names'] = $this->Model_Name->get_names();
$this->load->view('view_name', $data);

Your view:
Code:
foreach($names as $name) {
   echo "<option value='{$name['id']}'>{$name['name'}</option>";
}


Messages In This Thread
2 column table to form_dropdown array - by El Forum - 09-21-2012, 10:20 AM
2 column table to form_dropdown array - by El Forum - 09-21-2012, 10:30 AM
2 column table to form_dropdown array - by El Forum - 09-21-2012, 10:47 AM
2 column table to form_dropdown array - by El Forum - 09-21-2012, 11:01 AM
2 column table to form_dropdown array - by El Forum - 09-21-2012, 11:06 AM
2 column table to form_dropdown array - by El Forum - 09-21-2012, 11:10 AM
2 column table to form_dropdown array - by El Forum - 09-21-2012, 11:12 AM
2 column table to form_dropdown array - by El Forum - 09-21-2012, 11:33 AM
2 column table to form_dropdown array - by El Forum - 09-21-2012, 12:27 PM
2 column table to form_dropdown array - by El Forum - 09-22-2012, 02:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB