Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use LIKE OR operator using cakephp & mysql

Tags:

cakephp

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? Thanks..

like image 815
PHP Ferrari Avatar asked Jun 11 '10 12:06

PHP Ferrari


2 Answers

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".

like image 179
php geek Avatar answered Sep 30 '22 05:09

php geek


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"))
    )
));
like image 43
bancer Avatar answered Sep 30 '22 04:09

bancer