我需要在php cake中的if else条件中使用基本的“或”。
$oTourRecords = $this->Record->find('all', array(
'conditions' => array(
'record.builder_name' => 'rey',
'or' => array(
'record.builder_name' => 'norbert',
)
)
)
);
基本上我需要得到如果记录包含builder_name = rey或“norbert” 这个返回null。
答案 0 :(得分:4)
尝试
$oTourRecords = $this->Record->find('all', array(
'conditions' => array(
'OR' => array(
'record.builder_name' => 'norbert',
'record.builder_name' => 'rey',
)
)
));
答案 1 :(得分:2)
您可以通过多种方式实现:
$oTourRecords = $this->Record->findAllByBuilderNameOrBuilderName('rey', 'norbert');
$oTourRecords = $this->Record->find('all', array(
'conditions' => array(
'OR' => array(
'record.builder_name' => 'norbert',
'record.builder_name' => 'rey',
)
)
));
$oTourRecords = $this->Record->find('all', array(
'conditions' => array('record.builder_name IN ' => array('norbert','rey'))
));
答案 2 :(得分:1)
您还可以使用
IN
检索相似类型的数据,而不是OR
条件。
示例:
$oTourRecords = $this->Record->find('all', array(
'conditions' => array(
'record.builder_name IN'=>array(
'rey',
'norbert'
)
)
)
);