用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2525|回复: 3
收起左侧

[已解决] 怎么去掉optgroup ?

[复制链接]
发表于 2011-4-28 11:22:50 | 显示全部楼层 |阅读模式
控制器:

PHP复制代码
 $data['products'] = $this->article_model->get_products();
复制代码


模型:
PHP复制代码
 
function get_products()
     {
        //$query = $this->db->query('select * from products where id > 0');
        //return $query->result_array();
        $this->load->helper('form');
        //$query = $this->db->get('products');
        $query = $this->db->query('SELECT products FROM products');
        //$rows = $query->row_array();
        $rows = array();
        foreach ($query->result_array() as $row){
            $rows[] = $row;
        }
        return $rows;
     }
 
复制代码


视图:

PHP复制代码
 
        <?php echo form_dropdown('id', $products, '所属产品'); ?>
 
复制代码


实际效果:
HTML复制代码
 <select name="id">
<optgroup label="0">
<option value="products">产品1</option>
</optgroup>
<optgroup label="1">
<option value="products">产品2</option>
</optgroup>
</select>
复制代码
发表于 2011-4-28 11:24:14 | 显示全部楼层
不用这个函数就是了,自己写好啦
 楼主| 发表于 2011-4-29 11:58:37 | 显示全部楼层
已经解决了  是查询sql的问题
发表于 2011-4-29 12:06:42 | 显示全部楼层


foreach ($query->result_array() as $row){
    $rows[] = $row;
}
return $rows;

LZ多此一举啊。。。

本版积分规则