Active Record: WHERE(.. OR ..) AND .. |
[eluser]Buso[/eluser]
I need this: Code: SELECT * FROM table WHERE id = ? AND (status = ? OR ip = ?); Is it possible to do it with active record? This is what I have so far: Code: $this->db->where('id',$id); But it's not the same
[eluser]wh1tel1te[/eluser]
Code: $this->db->where('id',$id);
[eluser]wowdezign[/eluser]
This kind of stuff is exactly why I am starting to use more and more query binding. Your query above is almost already written to bind: Code: $sql="SELECT * FROM table WHERE id = ? AND (status = ? OR ip = ?)"; If you aren't passing in variables, I've had success with: Code: $sql="SELECT * FROM table WHERE id = 3 AND (status = 'somstatus' OR ip = 'x.x.x.x')"; I used to love active record. But, when I have a complex query, it's too hard for me to convert it. Since binding does the same thing, I just use it. :-) It's mentioned at the very bottom of this page in the manual: http://ellislab.com/codeigniter/user-gui...eries.html
[eluser]Buso[/eluser]
[quote author="wowdezign" date="1257910797"]This kind of stuff is exactly why I am starting to use more and more query binding. Your query above is almost already written to bind: Code: $sql="SELECT * FROM table WHERE id = ? AND (status = ? OR ip = ?)"; If you aren't passing in variables, I've had success with: Code: $sql="SELECT * FROM table WHERE id = 3 AND (status = 'somstatus' OR ip = 'x.x.x.x')"; I used to love active record. But, when I have a complex query, it's too hard for me to convert it. Since binding does the same thing, I just use it. :-)[/quote] yes I think im gonna stick to binding too.. active record has just lost its magic to me =( thanks |
Welcome Guest, Not a member yet? Register Sign In |