0

I need to fetch data from database and put it in my dropdownlist as choices so far nothing is showing in the dropdownlist

MODEL

function getAllGroups() { $query = $this->db->query('SELECT firstname FROM tblsec'); return $query->result(); } 

VIEW

 foreach($groups as $row) { echo '<option value="'.$row->firstname.'">'.$row->firstname.'</option>'; } ?> </select> 

CONTROLLER

public function salesorders() { if ($this->session->userdata('logged_in')) { $this->header2(); $data['groups'] = $this->secretary_model->getAllGroups(); $this->load->view('secretary/transactions'); } else { redirect('secretary/sec_login_view'); } } 
1
  • 1
    Please check Opening of SELECT TAG <select> Commented Apr 24, 2015 at 15:15

2 Answers 2

1

You didn't pass any data to your view.

$this->load->view() has an optional second parameter to supply data to your view from the controller. e.g. $this->load->view('secretary/transactions', $data)

You also don't define $data anywhere until $data['groups'] (Unless you just cut out some code)

Finally, the view will receive the passed data as $groups because that's what you are setting it to in the $data variable when you say $data['groups'], it turns the keys into variables.

Also, I would try outputting your database query on the page to see if it's successfully querying before putting it in the SELECT tag (just for easier debugging)

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

Controller

$data['groups'] = $this->secretary_model->getAllGroups(); $this->load->view('secretary/transactions', $data); 

View

$options = array(); foreach($groups as $group){ $options[$group->firstname] = $group->firstname; } echo form_dropdown('dropdownName', $options); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.