如何使用IN以逗号分隔的字符串在cakePHP中查找。

时间:2016-05-22 17:41:13

标签: php arrays cakephp

我正在做一个代码,我必须找到一些字符串在这里的东西。把那些代码放在上面。

$status = "free","busy"
// In database there is work_status is saved either as free, busy, onduty.....

I have to find whether driver is free , busy. want to put an array into condition.
$this->Driver->find ( 'all', array( 'conditions' => array( 'Driver.work_status' => array( $driver_status ) ));

但是空数组返回了......你能帮帮我吗?

1 个答案:

答案 0 :(得分:3)

这甚至都不是有效的PHP代码。只需将数组传递给条件,它就会创建IN查询:

$status = array("free","busy");
$this->Driver->find ( 'all', 
  array( 
    'conditions' => array( 
      'Driver.work_status' => $status 
    )
  )
);