CodeIgniter Forums
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);
        
        $this->db->or_like('keywords',$keyword);
        $this->db->where('city',$city);
        
        $this->db->orderby('companyname');
$this->db->get('ng_city');

it produces select * from ng_city where city='somecity' and companyname like '%somecompany%' or keywords like '%somekeyword%';

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%');
This way the result of keywords and companyname is produced first before compared with city.
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