I have a site devloped in codeigniter where I'd want to create a query with some condition and a condition inside with OR like this:
Select * from users where username = 'user' and nation_id = 90 and active = 1 and (rate = 1 OR rate = 2 OR rate = 3);
Now I have create this code but isn't working because is like writing this:
Select * from users where username = 'user' and nation_id = 90 and active = 1 and rate = 1 OR rate = 2 OR rate = 3;
I don't want this query but the first. This is my code:
$this->db->from('users');
$this->db->where('username', 'user');
$this->db->where('nation_id', 90);
$this->db->where('active', 1);
for ($i = 1; $i<=3; $i++){
$this->db->or_where('rate', $i);
}
$query = $this->db->get();
Please don't tell me other way like write the query manually because I have simplified it and is where huge to make a manual query.
The cycle is important that is in that way because I have to cycle an array for example.
I only want to insert my or condition inside a ()
is possible?
service
...not fromusers
, right? – jcorry Aug 7 '13 at 15:52BETWEEN
– Brewal Aug 7 '13 at 16:01