martes, 18 de febrero de 2020

Cakephp 3 query with conditions array build in foreach loop

Hello i want to use an array as condition. For example i have services with a zip as combination 12345 => cleaning, 54321 => cleaning now i build my array together in a foreach loop $searcharray = []; foreach($services as $key => $val){ searcharray[] = array('service' => $val['service'], 'zip' => $val['zip']); } My search array lookes like this: [ (int) 0 => [ 'service' => 'cleaning', 'zip' => '12345' ], (int) 1 => [ 'service' => 'cleaning', 'zip' => '54321' ] ] Then i try to get the data from my request table $this->loadModel('Requests'); $openrequests = $this->Requests->find('all', array( 'conditions' => array( 'OR' => array( $searcharray ) ) )); It didnt work maybe of the keys in the array, because i set after the $searcharray for example [1] and then it works. I dont want to write the condition as string, but how can i solve it?
http://dlvr.it/RQHwxc

No hay comentarios:

Publicar un comentario