[eluser]PlesaCarmen[/eluser]
Hi, I am new in codeigniter, I want to populate a dropdown from database and i don't know how to start.
I have 10 tables in a database printer.Every tables has a type, price and id.
My questions is how to populate each table in a dropdown?
I using the code and I get this error:
My model:
class Model_print_run extends CI_Model{
public function get_dropdown()
{
$result=$this->db->get('print_run');
$dropdown=array();
foreach($result->result_array() as $row)
{
$dropdown[$row['id']]=$row['type'];
}
return $dropdown;
}
}
My controller:
class print_run extends CI_Controller{
public function index()
{
$this->load->model('model_print_run');
$data['print_run']= $this->model_print_run->get_dropdown();
$this->load->view('print_run_view', $data);
}
}
My view:
echo form_dropdown('print_run', $dropdown);
I using the code and I get this error:
Severity: Notice
Message: Undefined variable: dropdown
Filename: views/print_run_view.php
Line Number: 2
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: helpers/form_helper.php
Line Number: 331
Thank you!
Any suggest will be help!