2015-04-01 69 views
0

我正在codeigniter中工作。我的问题是我想显示具有相同ID的所有行。但是当我执行group_by时,它只输出该组的一行。下面在Codeigniter中选择('*')with group_by

是我的模型

function category_content(){ 
     $this->db->select('*'); 
     $this->db->from('category'); 
     $this->db->group_by('category_id'); 
     $query = $this->db->get(); 
     return $query->result_array(); 
    } 

请帮助。

+0

,而不是由,如果你想获得特定ID的记录然后通过使用where子句组ID – 2015-04-01 12:22:16

+0

使用顺序组使用顺序是使用的时候,需要把相同的行。 – 2015-04-01 12:35:45

回答

1

根据sql属性Group By将所有匹配的记录分组,并只会显示一个。看来你想按id排序。然后,它能够更好地在你的情况下使用order by

0

参见示例希望你会了解这个..

tableA 
    _____ 
    id name marks 
    -- ---- --- 
    1 x  25 
    2 y  27 
    1 z  30 


    SELECT * FROM tableA group by id 

OUTPUT: 
1 x 25 
2 y 27 

你应该使用WHERE子句。

SELECT * FROM tableA WHERE id=1 

OUTPUT: 
1 x 25 
1 z 30 


    function category_content(){ 
      $this->db->select('*'); 
      $this->db->from('category'); 
      $this->db->where($category_id); 
      $query = $this->db->get(); 
      return $query->result_array(); 
     } 

https://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html