我想使用组合框从数据库中获取 nim,但我的组合框没有显示任何内容
我的 Controller
public function add(){
// Ambil data perusahaan dari tabel perusahaan
//$this->Super_Model->get('t_mynetpoin');
$data['nim'] = $this->Super_Model->query('select nim from t_mynetpoin');
// End of Ambil Data perusahaan
$data['view']= 'v_super_admin/super_admin_template/v_sidebar';
$data['view']= 'v_super_admin/Coin/v_form';
$this->load->view('index',$data);
}
我的模型
public function query($sql=''){
$query = $this->db->query($sql);
if($query){
return $query->result();
}else{
return print_r($this->db->last_query());
}
View 中的我的组合框
<div class="form-group">
<label class="col-sm-2 control-label">Nim </label>
<div class="col-sm-10">
<?php echo form_dropdown("nim", $nim, @$row->nim, 'class="form-control" id="nim"'); ?>
</div>
</div>
已更新
我的表结构
|id_mynetpoin|tot_poin|last_modified|nim |
|1 |7000 |2016-05-20 |1314115315|
最佳答案
$query->result();
这将返回对象数组,而对于下拉列表,您将需要一个带有键值对的数组 因此运行一个循环并覆盖类似于下面数组的结果,
$options = array(
'small' => 'Small Shirt',
'med' => 'Medium Shirt',
'large' => 'Large Shirt',
'xlarge' => 'Extra Large Shirt',
);
$shirts_on_sale = array('small', 'large');
echo form_dropdown('shirts', $options, 'large');
https://ellislab.com/codeigniter/user-guide/helpers/form_helper.html
在你的 Controller 中, 而不是下面的行
已更新 $data['nim'] = $this->Super_Model->query('从 t_mynetpoin 选择 nim'); 写下下面的代码
$result = $this->Super_Model->query('select nim from t_mynetpoin');
$options = array();
foreach ($result as $r){
$options []= $r->nim;
}
$data['nim'] = $options;
关于php - 组合框上的空值 - codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37337965/