开发者

How to use LIKE OR operator using cakephp & mysql

开发者 https://www.devze.com 2023-01-02 22:47 出处:网络
I am new to cakephp & don\'t know what is the syntax to use LIKE & OR operator in cakephp with mysql.

I am new to cakephp & don't know what is the syntax to use LIKE & OR operator in cakephp with mysql.

Can anyone help me? Th开发者_如何学Goanks..


Complex find conditions from the manual:

$this->Post->find('first', array (
    "Author.name" => "Bob", 
    "OR" => array (
        "Post.title LIKE" => "%magic%",
        "Post.created >" => date('Y-m-d', strtotime("-2 weeks"))
    )
));


you can use: for "like"

$this->Post->find("all",array('condition'=>array('Author LIKE'=>"ad%")));

above query will give You the data from table posts where author name starts with "ad".

for "OR"

$this->Post->find("all",array('condition'=>array("OR"=>array('Author LIKE'=>"ad%",'Post LIKE'=>"bo%"))));

above query will give You the data from table posts where author name starts with "ad" OR Post starts with "bo".


if you using where function then use this :-

->where(['Products.category_id'=>1, 'Products.name LIKE' =>'test%'])

thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消