Welcome Guest, Not a member yet? Register   Sign In
Order of precedence Active Record
#1

[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.
#2

[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
#3

[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')");
#4

[eluser]chinedubond[/eluser]
Thanks a lot for your help.It was very useful




Theme © iAndrew 2016 - Forum software by © MyBB