Order of precedence Active Record - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Order of precedence Active Record (/showthread.php?tid=8473) |
Order of precedence Active Record - El Forum - 05-19-2008 [eluser]chinedubond[/eluser] I HAVE THIS PROBLEM Code: $this->db->like('companyname',$keyword); The problem is the query searches city and companyname if true then searches keywords i don't want that.What i want is a situation where i can get the active record to produce this result. Code: select * from ng_city where city='somecity' and ( companyname like '%somecompany%' or keywords like '%somekeyword%'); Please how can achieve this with active record. Thank you. Order of precedence Active Record - El Forum - 05-20-2008 [eluser]Andreas Krohn[/eluser] Try using $this->db->query("select * from ng_city where city='".$somecity."' and ( companyname like '%".$somecompany."%' or keywords like '%".$somekeyword."%'"). That way you can assemble the query whatever way you want. /Andreas Order of precedence Active Record - El Forum - 05-20-2008 [eluser]xwero[/eluser] in AR there is no possibility to add backets so the only option is to put the where part in a string Code: $this->db->where("city='$city' and ( companyname like '$company' or keywords like '$keyword')"); Order of precedence Active Record - El Forum - 05-20-2008 [eluser]chinedubond[/eluser] Thanks a lot for your help.It was very useful |