Jc John
Jc John

Reputation: 1859

How to write a WHERE not equal condition in a CodeIgniter SELECT query?

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();

Upvotes: 1

Views: 1022

Answers (3)

kishor10d
kishor10d

Reputation: 553

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.

Upvotes: 1

Hikmat Sijapati
Hikmat Sijapati

Reputation: 6994

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();

Upvotes: 0

infinityKK
infinityKK

Reputation: 40

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();

Upvotes: 0

Related Questions