php - Getting a drop down list from a database in CodeIgniter -
i new codeigniter , have been trying populate drop down list on view page data database no success. tried using recomendations question drop down still empty (display data database dropdown codeigniter)
here view:
<label>city</label> <select class="form-control> <option value="">all</option> <?php foreach($groups $city) { echo '<option value="'.$city['cityidd'].'">'.$city['city'].'</option>'; } ?> </select> <br/>
here controller:
<?php class main_controller extends ci_controller { function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->database(); } public function index() { $this->load->helper('form'); $this->load->view('supplier_add'); } }
here model:
class site_model extends ci_model { public function __construct() { /* call model constructor */ parent::__construct(); } function getallgroups() { $query = $this->db->query('select city citys'); return $query->result(); } }
the table name "citys" corresponding column heads "cityidd" , "city"
there several issue found there. make changes below
function __construct(){ parent::__construct(); $this->load->helper('url'); $this->load_model('site_model'); $this->load->database(); } public function index(){ $this->load->helper('form'); $data['groups'] = $this->site_model->getallgroups(); $this->load->view('supplier_add',$data); }
finally model
function getallgroups(){ $query = $this->db->query('select cityidd,city citys'); return $query->result_array(); }
and test
Comments
Post a Comment