Welcome Guest, Not a member yet? Register   Sign In
Can't I use db->where and db->like together?
#1

[eluser]esset[/eluser]
Hey

I'm trying to do this using the Active Record class.

Code:
$this->db->where(foo);
$this->db->like(foo);
$this->db->or_like(fooo);

Why when I run this is my WHERE statement ignored?

I wan't it to produce:
Code:
SELECT * FROM foo WHERE foo = foo AND foo LIKE '%%' OR foo LIKE '%%'
#2

[eluser]toopay[/eluser]
Above AR will generates your needs, nothing wrong with that, but i guess, you expect a query like this
Code:
SELECT * FROM foo_table WHERE foo = 'bar' AND (foo LIKE '%b%' OR foo LIKE '%ar%')
and unfortunately, AR is not supported that type of query.
#3

[eluser]esset[/eluser]
Ah yes stupid me. I just couldn't figure out why it wasn't working. Got code-blind Smile

Is there a workaround way I could achieve this with AR anyways, like this?

Code:
$this->db->where(foo);
$this->db->like(bar);
$this->db->or_like(bars);
$this->db->like(bar);
$this->db->where(foo);

? Smile
#4

[eluser]toopay[/eluser]
The CI ActiveRecord not supported for grouped WHERE (like you experienced) and sub-query.
#5

[eluser]esset[/eluser]
Gotcha! Thanks
#6

[eluser]osci[/eluser]
OR vs. AND in Active Record LIKE query
And I don't think it's not supported, seems more to me like a bug, a minor one, but still a bug.

Edit: sorry, misread the thread, toopay is right about nested queries




Theme © iAndrew 2016 - Forum software by © MyBB