0

请我对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;
4

2 回答 2

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";
于 2018-07-25T12:49:28.893 回答
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

于 2018-07-25T14:19:27.260 回答