Welcome Guest, Not a member yet? Register   Sign In
foreach outputting array?

Okay i have another noobish question what im attempting to do is a foreach statement from a query and have it outputted as an array or some way that i could use the results with the form_dropdown() function in CI any ideas?

Example on your view file

<select name="">
  &lt;?php foreach($array_result as $row): ?&gt;
  <option value="&lt;?php echo $row->value; ?&gt;">&lt;?php echo $row->value; ?&gt;</option>
  &lt;?php endforeach; ?&gt;

I hope it helps

in your model

function get_combo()
   $query = $this->db->from('table')->select('id, displayfield')->get();

   if($query->num_rows() > 0) {
   foreach ($query->result() as $row) {
      $data[$row->id] = $row->displayfield;
   return $data;

in your controiller
$data['rs_combo'] = $this->your_model->get_combo();
$this->load->view('view', $data);

in your view

&lt;?php echo form_dropdown('name', $rs_combo); ?&gt;

Theme © iAndrew 2016 - Forum software by © MyBB