douli2063 2016-05-20 04:30
浏览 28

组合框上的空值 - codeigniter

I want to get nim from database using combobox but my combobox not show anything

My controler

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);

}

My model

public function query($sql=''){
$query = $this->db->query($sql);
if($query){
  return $query->result();
}else{
  return print_r($this->db->last_query());
}

My Combobox In 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>

Updated

My Table Structure

|id_mynetpoin|tot_poin|last_modified|nim       |
|1           |7000    |2016-05-20   |1314115315|
  • 写回答

1条回答 默认 最新

  • douou8954 2016-05-20 06:06
    关注
    $query->result();
    

    this will return array of objects while for dropdown you will need an array with key value pair so run a loop and coveret your result simmilar to below array,

    $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
    

    In your controller, Instead of below line

    updated $data['nim'] = $this->Super_Model->query('select nim from t_mynetpoin'); write below code

    $result =  $this->Super_Model->query('select nim from t_mynetpoin');
            $options = array();
            foreach ($result as $r){
            $options []= $r->nim;
            }
            $data['nim'] = $options;
    
    评论

报告相同问题?

悬赏问题

  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图