2012-08-09 79 views
0

我试试这个代码如何从不同的表格(字段x)中选择所有字段?笨

function catstore($id) 
    { 
     $this->db->distinct(); 
     $this->db->select('store_id'); 
     $this->db->from('products'); 
     //$this->db->join('products','products.store_id = products.store_id'); 
     $this->db->where('cat_id', $id); 
     $result = $this->db->get(); 
     return $result->result();  
    } 

它只产生不同STORE_ID,但我想用基于STORE_ID不同行的表的所有列

推荐我的任何选项提前

谢谢

回答

0

完全可以省略select函数。如果您从表中选择全部(*),则不需要使用此功能。如果省略,笨假设你想SELECT *

http://codeigniter.com/user_guide/database/active_record.html#select

或..

您可以通过逗号分隔值select功能。因此,通过要选择

function catstore($id) 
    { 
     $this->db->distinct(); 
     $this->db->select('store_id, column1, column2, cloumn3'); 
     $this->db->from('products'); 
     //$this->db->join('products','products.store_id = products.store_id'); 
     $this->db->where('cat_id', $id); 
     $result = $this->db->get(); 
     return $result->result();  
    } 
+0

无法正常工作..... – 2012-08-09 12:45:00

1

用逗号分隔的所有列名,您可以尝试使用GROUP_BY

function catstore($id) 
{ 
    $this->db->select('*'); 
    $this->db->from('products'); 
    //$this->db->join('products','products.store_id = products.store_id'); 
    $this->db->where('cat_id', $id); 
    $this->db->group_by('store_id'); 
    $result = $this->db->get(); 
    return $result->result();  
} 

我知道这个问题已经是很久以前的事,但有可能会寻找相同像我这样的问题,这就是我解决问题的方法。

相关问题