0

我试试这段代码

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 的不同行

建议我任何选择

提前致谢

4

2 回答 2

3

您可以尝试使用 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();       
}

我知道这个问题已经很久了,但是可能有人正在寻找和我一样的问题,这就是我解决它的方法。

于 2016-09-15T03:46:51.453 回答
0

您可以完全省略该select功能。如果您从表中选择所有 (*),则不需要使用此功能。省略时,CodeIgniter 假定您希望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();       
    }
于 2012-08-09T09:48:06.450 回答