![]() |
OR in codeigniter query.. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: OR in codeigniter query.. (/showthread.php?tid=57082) |
OR in codeigniter query.. - El Forum - 02-13-2013 [eluser]Musaddiq Khan[/eluser] Hi, I want to generate SQL query through codeigniter function. I have code as below. Code: $this->db->distinct(); Code: SELECT DISTINCT `pkItemId`, `item`.`Name` FROM (`items`) WHERE `item`.`Is_Item` <> 0 AND `item`.`Status` = '1' AND `item`.`Model_Name` LIKE '%S1S38R%' OR `item`.`Name` LIKE '%S1S38R%' OR `item`.`sku_no` LIKE '%S1S38R%' OR `item`.`SKU` LIKE '%S1S38R%' But I want that the OR clauses should be grouped as below. Code: SELECT DISTINCT `pkItemId`, `item`.`Name` FROM (`items`) WHERE `item`.`Is_Item` <> 0 AND `item`.`Status` = '1' AND (`item`.`Model_Name` LIKE '%S1S38R%' OR `item`.`Name` LIKE '%S1S38R%' OR `item`.`sku_no` LIKE '%S1S38R%' OR `item`.`SKU` LIKE '%S1S38R%') OR in codeigniter query.. - El Forum - 02-13-2013 [eluser]Aken[/eluser] Same problem AGAIN. OR in codeigniter query.. - El Forum - 02-14-2013 [eluser]Musaddiq Khan[/eluser] I've searched and found some sort of solution. Code: $str = "(item.Model_Name LIKE '%$search_key%' OR item.Name LIKE '%$search_key%' OR item.sku_no LIKE '%$search_key%' )"; wich generate the following query in the structure which is needed. Code: SELECT DISTINCT `pkItemId`, `item`.`Name`, `item`.`url_slug`, FROM (`items`) WHERE (item.Model_Name LIKE '%S1S38R%' OR item.Name LIKE '%S1S38R%' OR item.sku_no LIKE '%S1S38R%') AND `item`.`Is_Item` <> 0 AND `item`.`Status` = '1' |