请帮帮我如何将此查询转换为codeigniter查询格式
SELECT *
FROM `table1`
LEFT JOIN `table2`
ON table1.permission_key = table2.permission_key AND
(table2.role_id is null || table2.role_id="1")
WHERE
table1.section ='abc' AND
table1.sub_section = 'xzy';
答案 0 :(得分:0)
您好,请尝试以下
$this->db->select('table1.*')
->from('table1')
->join('table2', 'table1.permission_key=table2.permission_key AND (table2.role_id is null OR table2.role_id="1")', 'left')
->where('table1.section', 'abc')
->where('table1.sub_section', 'xzy')
->result_array();
答案 1 :(得分:0)
您可以将查询键入普通sql语句并将其传递给codeiginter
函数$this->db->query();
$query = "SELECT * FROM table1 JOIN table2 ON table1.permission_key = table2.permission_key AND AND
(table2.role_id is null || table2.role_id='1')
WHERE table1.section ='abc' AND table1.sub_section = 'xzy'";
$this->db->query($query);
$this->db->get();
答案 2 :(得分:0)
试试这个。
$wherearraydata = array('table1.section' => 'abc', 'table1.sub_section' => 'xyz');
$this->db->select('*');
$this->db->from('table1');
$this->db->join('table2', 'table2.permission_key = table1.permission_key' AND (table2.role_id is null OR table2.role_id="1"));
$this->db->where($wherearraydata);
$querydata = $this->db->get();
return $querydata->result_array();