请我对codeigniter有问题。当我尝试在此处登录时就是结果
下面是我的代码:
$sub_and = '';
if($this->location_parent == 0){
$sub_and = "and g.idlocation_fk IN (".$locids.")";
}else{
$sub_and = "and g.idlocation_fk IN (".$locids.")";
}
if(($this->session->userdata("user_group_fk") == 1) || ($locids == '')){
$sub_and = '';
}
$sql = "select GROUP_CONCAT(DISTINCT(g.idgroup)) as group_id
FROM groups g
JOIN group_users gu ON gu.idgroup_fk = g.idgroup
WHERE gu.status = 0 and gu.iduser_fk = $iduser $sub_and";
$results = $this->db->query($sql);
$results = $results->row_array();
return $results;
答案 0 :(得分:0)
连接时出错。 尝试以下。
$sql = "select GROUP_CONCAT(DISTINCT(g.idgroup)) as group_id FROM groups g JOIN group_users gu ON gu.idgroup_fk = g.idgroup WHERE gu.status = 0 and gu.iduser_fk = $iduser." ".$sub_and";
答案 1 :(得分:0)
希望这对您有帮助:
确保方法中可用$iduser
,并且$locids
应该是一个值数组
$this->db->select('GROUP_CONCAT(DISTINCT(g.idgroup)) as group_id');
$this->db->from('groups g');
$this->db->join('group_users gu', 'gu.idgroup_fk = g.idgroup');
$this->db->where('gu.status', '0');
$this->db->where('gu.iduser_fk', $iduser);
/* $locids must be an array like $locids = array(1,3,4);*/
if (! empty($locids))
{
$this->db->where_in('g.idlocation_fk', $locids);
}
$row = $this->db->get()->row_array();
print_r($row);
更多信息:https://www.codeigniter.com/user_guide/database/query_builder.html