Welcome Guest, Not a member yet? Register   Sign In
how to do this query
#1

[eluser]gebe[/eluser]
how to do this query with active record class?

WHERE
(field = 'negocio' OR field IS NULL)
AND
other_field = 1

Thanks
#2

[eluser]Clooner[/eluser]
What did you try yourself?

How AR works is really well documented: http://ellislab.com/codeigniter/user-gui...tml#select.
#3

[eluser]siubie[/eluser]
hai Smile interesting, dunno this is my bad on my code @_@

if i make this AR

Code:
$this->db->where('field1',$var1);
$this->db->or_where('name',$name);
$this->db->where('gotcha',$var2);

result in query

Code:
where field1=john and name=doe and gotcha=hehe

maybe this question point to how we make the query to

Code:
where ( field1=john or name=doe ) and gotcha=hehe
#4

[eluser]danmontgomery[/eluser]
AR doesnt' support grouped where statements, you woulud need to do it manually.

Code:
$this->db->where('(`field1` = "'.$var1.'" OR `field2` IS NULL)', null, false)->where('field3', 'some value');
#5

[eluser]gebe[/eluser]
Hi Clonner, I already read the document, but is not enought for do my query.
I try with or_where, where_in, etc, etc

Exactly siubie I need the query:

WHERE (field=x OR field IS NULL) AND field_2 = b
#6

[eluser]gebe[/eluser]
OK nocturn, Thanks
#7

[eluser]Clooner[/eluser]
[quote author="gebe" date="1276829361"]Hi Clonner, I already read the document, but is not enought for do my query.
I try with or_where, where_in, etc, etc

Exactly siubie I need the query:

WHERE (field=x OR field IS NULL) AND field_2 = b[/quote]

From the manual
Code:
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);

change it into
Code:
$where = "(name='Joe' OR status='active') AND status='boss' ";
$this->db->where($where);




Theme © iAndrew 2016 - Forum software by © MyBB