而且还是在cakephp 2.0中的条件

时间:2015-01-27 08:01:11

标签: cakephp

CakePhp中查找查询中的条件数组是什么。 MySql查询是:

sc.country = '".$country."' and (sc.city='".$city."' or sc.state='".$city."')

2 个答案:

答案 0 :(得分:2)

你可以这样做(甚至在documentation中提到)

$conditions=array(
    "sc.country" => "yourcondition",
    "OR" => array(
        "sc.city" => "cityname",
        "sc.state" => "statename"
    )
));

输出将是: -

sccountry ='yourcondition'和((sccity ='cityname')或(scstate ='statename'))

答案 1 :(得分:1)

您应该尝试此代码

$this->YourModel->find('all',array(
    'conditions'=>array(
        'sc.country'=>"$country",
        'OR'=>array('sc.city'=>"$city",
            'Or'=>array('sc.state'=>"$city")
            )   
        )   
        )
    );

以下是我的演示代码sqldump

enter image description here