CakePhp中查找查询中的条件数组是什么。 MySql查询是:
sc.country = '".$country."' and (sc.city='".$city."' or sc.state='".$city."')
答案 0 :(得分:2)
你可以这样做(甚至在documentation中提到)
$conditions=array(
"sc.country" => "yourcondition",
"OR" => array(
"sc.city" => "cityname",
"sc.state" => "statename"
)
));
输出将是: -
sc
。country
='yourcondition'和((sc
。city
='cityname')或(sc
。state
='statename'))
答案 1 :(得分:1)
您应该尝试此代码
$this->YourModel->find('all',array(
'conditions'=>array(
'sc.country'=>"$country",
'OR'=>array('sc.city'=>"$city",
'Or'=>array('sc.state'=>"$city")
)
)
)
);
以下是我的演示代码sqldump