How to add multiple conditions for a single column?

906 Views Asked by At

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%'
),
1

There are 1 best solutions below

1
On BEST ANSWER

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%')
    )
),