This question already has an answer here:
Codeigniter:
$this->db->select("item.*");
$this->db->from("items");
$this->db->where_not_in('item.ID', $Not);
$this->db->where_in('item_sub_category.Sub_category', $Sub_category);
$this->db->or_where_in('item_category.Category',$Category, NULL, FALSE);
$this->db->limit(4);
return $this->db->get()->result_array();
Output:
SELECT `item`.*
FROM `item`
LEFT JOIN `item_category`
ON `item_category`.`item` = `item`.`id`
LEFT JOIN `item_sub_category`
ON `item_sub_category`.`item` = `item`.`id`
WHERE `item`.`id` NOT IN( '12' )
AND `item_sub_category`.`sub_category` IN( '65', '66', '67', '68' )
OR `item_category`.`category` IN( '35', '36' )
LIMIT 4
Expected Output:
SELECT `item`.*
FROM `item`
LEFT JOIN `item_category`
ON `item_category`.`item` = `item`.`id`
LEFT JOIN `item_sub_category`
ON `item_sub_category`.`item` = `item`.`id`
WHERE `item`.`id` NOT IN( '12' )
AND (`item_sub_category`.`sub_category` IN( '65', '66', '67', '68' )
OR `item_category`.`category` IN( '35', '36' ))
LIMIT 4
Can anyone please tell me How can I achieve my expected output by using active record?
</div>