我试试这个代码
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的不同行
建议我任何选择
提前致谢
您可以尝试使用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();
}
我知道这个问题很久以前了,但一个人可能和我一样正在寻找同样的问题,这就是我解决它的方式。
你可以完全省略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();
}