Active Record "where()->or_like()" generates "AND LIKE" not "OR LIKE"! |
[eluser]TomsB[/eluser]
Code: $query = $this->db->select('id') SELECT `id` FROM (`table`) WHERE `id` IN (5, 3, 6, 7) AND `name` LIKE '%test%' OR `name` LIKE '%test2%' But I need to get: SELECT `id` FROM (`table`) WHERE `id` IN (5, 3, 6, 7) OR `name` LIKE '%test%' OR `name` LIKE '%test2%' I'm stuck with this for about two hours now.. Is this even possible to get "OR"?
[eluser]adamfairholm[/eluser]
I could be proven wrong, but I don't believe CI's Active Record can do that. I've taken a look at the active record class, and I haven't found a place where there is a provision for that. You could try Ignited Query, which has the ability to handle nested WHERE statements, and probably can handle the nested WEHRE/LIKE statements the way you'd like.
[eluser]xwero[/eluser]
what do you get if you do this Code: $this->db->select('id');
[eluser]TomsB[/eluser]
I get: Code: Array I am experimenting with this right now: Code: ...
[eluser]xwero[/eluser]
The problem is that the first item no OR has which means an AND is added. This is a bug in the AR library. Code: $prefix = (count($this->ar_like) == 0) ? '' : $type; Code: if (count($this->ar_like) > 0) Code: if (count($this->ar_like) > 0)
[eluser]TomsB[/eluser]
With changes you suggested I get: SELECT `id` FROM (`table`) WHERE `id` IN (5, 3, 6, 7) `name` LIKE ‘%test%’ OR `name` LIKE ‘%test2%’ There is no OR or AND: `id` IN (5, 3, 6, 7) OR|AND `name` LIKE ‘%test%’
[eluser]xwero[/eluser]
What is this output Code: $this->db->select('id');
[eluser]TomsB[/eluser]
Code: Array Message: Undefined variable: prefix If I execute this code with changed DB_active_rec.php, I get the same problem - without OR or AND. |
Welcome Guest, Not a member yet? Register Sign In |