codeigniter not equal query error

我们两清 提交于 2021-02-11 08:20:52

问题


How can i do not equal in my query in mysql database to codeigniter framework. My query shows not equal to the position of admin. Here is my query

$query = $this->db->query('SELECT tbl_user_type.position, tbl_users.user_id, tbl_users.user_fname, tbl_users.user_lname,
                    tbl_users.user_mname FROM tbl_users INNER JOIN tbl_user_type ON tbl_users.user_type = tbl_user_type.user_type 
                    WHERE !(tbl_user_type.position = Admin) ');
        return $query->result();

回答1:


Please use active records query to do this task, it will be more simple with active records in codeigniter.

$this->db->select("UT.position, U.user_id, U.user_fname, U.user_lname, U.user_mname");
$this->db->from("tbl_users AS U");
$this->db->join("tbl_user_type AS UT", "U.user_type = UT.user_type"); 
$this->db->where("UT.position !=", "Admin");
$query = $this->db->get();

return $query->result();

Replace your query with above code. It will solve your problem.




回答2:


try following one.

$query = $this->db->query('SELECT tbl_user_type.position, tbl_users.user_id, tbl_users.user_fname, tbl_users.user_lname,
                tbl_users.user_mname FROM tbl_users INNER JOIN tbl_user_type ON tbl_users.user_type = tbl_user_type.user_type 
                WHERE tbl_user_type.position != "Admin" ');
    return $query->result();

OR

    $query = $this->db->query('SELECT tbl_user_type.position, tbl_users.user_id, tbl_users.user_fname, tbl_users.user_lname,
                tbl_users.user_mname FROM tbl_users INNER JOIN tbl_user_type ON tbl_users.user_type = tbl_user_type.user_type 
                WHERE tbl_user_type.position <> "Admin" ');
    return $query->result();



回答3:


Try it...

$this->db->where('tbl_user_type.position !=','Admin');
$query = $this->db->query('SELECT tbl_user_type.position, tbl_users.user_id, tbl_users.user_fname, tbl_users.user_lname,
                    tbl_users.user_mname FROM tbl_users INNER JOIN tbl_user_type ON tbl_users.user_type = tbl_user_type.user_type');
 return $query->result();


来源:https://stackoverflow.com/questions/41097300/codeigniter-not-equal-query-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!