如何在Codeigniter模型中编写此查询


SELECT user_name, user_dept, user_level
FROM tbl_users
WHERE (user_dept = 'Admin' AND user_level = '2') OR (user_level = '3');

我需要在CI模型函数中写这个。我试过的是

function getForwardvalues($uname)
{
$query = $this->db->select('user_name')->from('tbl_users')->where('user_dept'= $uname && 'user_level'='2')->or_where('user_level'='3')->get();
return $query->result();
}

我也试过了,但我没有得到我想要的

function getForwardvalues($uname)
{
$query = $this->db->select('user_name')
->from('tbl_users')
->group_start()
->where('user_dept =', $uname)
->where('user_level=', '2')
->group_end()
->or_where('user_level=','3')
->get();

return $query->result();
}

尝试这个

function getForwardvalues($uname)
{
$this->db->select('user_name, user_dept, user_level');
$this->db->from('tbl_users');
$this->db->where('(user_dept = "'.$uname.'" AND user_level = 2)')->or_where('user_level', 3);
$query = $this->db->get();
return $query->result();
}
function getForwardvalues($uname)
{
$user_dept="Admin";
$user_level="3"; 
$query = $this->db->select("user_name, user_dept, user_level")
->from("tbl_users")
->where("user_dept",$user_dept)
->where("user_level",$user_level)
->or_where("user_level ",'3')
->get();
return $query->result();

}

相关内容

  • 没有找到相关文章

最新更新