请告诉我代码点火器有问题。当我尝试在这里登录时,结果是
下面是我的代码:
$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;
连接时出现错误。请尝试以下内容。
$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";
希望这将帮助您:
确保$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