onice 发表于 2011-4-28 11:22:50

怎么去掉optgroup ?

控制器:

$data['products'] = $this->article_model->get_products();

模型:

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 echo form_dropdown('id', $products, '所属产品'); ?>


实际效果:
<select name="id">
<optgroup label="0">
<option value="products">产品1</option>
</optgroup>
<optgroup label="1">
<option value="products">产品2</option>
</optgroup>
</select>

jeongee 发表于 2011-4-28 11:24:14

不用这个函数就是了,自己写好啦

onice 发表于 2011-4-29 11:58:37

已经解决了是查询sql的问题

lamtin 发表于 2011-4-29 12:06:42



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

LZ多此一举啊。。。
页: [1]
查看完整版本: 怎么去掉optgroup ?