php - codeigniter form_dropdown, set option value without an array -
i want fetch table has 2 columns: id , name, , want column id value each option, , column name option name
this controller
//populate provinsi $this->load->model('provinsi'); $provinsi = $this->provinsi->get(); $this->load->view('admin/pages/product_form', array( 'provinces' => $provinsi, ));
and in view
<?php $options_provinsi = array('select_one' => 'select one'); foreach ($provinces $provinsi) { $options_provinsi[] = array( $provinsi->id => $provinsi->nama, ); } $extra = 'id="provinsi" class="form-control" onchange="loadlocation('provinsi','kota');"'; echo form_dropdown('provinsi', $options_provinsi, 'select_one', $extra); ?>
how set option value without using array?
replace foreach loop
foreach ($provinces $provinsi) { $options_provinsi[$provinsi->id] = $provinsi->nama; }
and in view
$extra = null; echo form_dropdown('provinsi', $options_provinsi, 'select_one', $extra);
Comments
Post a Comment