问题
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