Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple conditions for a single column?

I have many sentences that I need filter for a same column:

'conditions' => array('Zona.nombre LIKE' => $buscar,
                      'Zona.nombre LIKE' => 'CUPONATIC%',
                      'Zona.nombre LIKE' => 'GROUPON%'
),
like image 536
frtgu34 Avatar asked Oct 19 '25 18:10

frtgu34


1 Answers

your question is not very clear but I suppose the problem is that you use multiple time the same array key

You don't even mention the cakephp version but it seems cake2

If I remember well the workaround for cake2 is putting every condition in a different array

'conditions' => array(
     array('Zona.nombre LIKE' => $buscar),
     array('Zona.nombre LIKE' => 'CUPONATIC%'),
     array('Zona.nombre LIKE' => 'GROUPON%')
),

edit: of course this way you'll have the 3 conditions joined in AND.

It seems more logical to put them in OR so

'conditions' => array(
    'OR' => array(
         array('Zona.nombre LIKE' => $buscar),
         array('Zona.nombre LIKE' => 'CUPONATIC%'),
         array('Zona.nombre LIKE' => 'GROUPON%')
    )
),
like image 113
arilia Avatar answered Oct 22 '25 06:10

arilia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!