cakephp 2.0 中的 And Or 条件
And Or condition in cakephp 2.0
CakePhp 的查找查询中的条件数组是什么。
MySql 查询是:
sc.country = '".$country."' and (sc.city='".$city."' or sc.state='".$city."')
你应该试试这个代码
$this->YourModel->find('all',array(
'conditions'=>array(
'sc.country'=>"$country",
'OR'=>array('sc.city'=>"$city",
'Or'=>array('sc.state'=>"$city")
)
)
)
);
下面是我的演示代码sqldump
你可以这样做(甚至在 documentation 中提到)
$conditions=array(
"sc.country" => "yourcondition",
"OR" => array(
"sc.city" => "cityname",
"sc.state" => "statename"
)
));
输出将是:-
sc
.country
= 'yourcondition' AND ((sc
.city
='cityname') 或 (sc
.state
= 'statename'))
CakePhp 的查找查询中的条件数组是什么。 MySql 查询是:
sc.country = '".$country."' and (sc.city='".$city."' or sc.state='".$city."')
你应该试试这个代码
$this->YourModel->find('all',array(
'conditions'=>array(
'sc.country'=>"$country",
'OR'=>array('sc.city'=>"$city",
'Or'=>array('sc.state'=>"$city")
)
)
)
);
下面是我的演示代码sqldump
你可以这样做(甚至在 documentation 中提到)
$conditions=array(
"sc.country" => "yourcondition",
"OR" => array(
"sc.city" => "cityname",
"sc.state" => "statename"
)
));
输出将是:-
sc
.country
= 'yourcondition' AND ((sc
.city
='cityname') 或 (sc
.state
= 'statename'))