How to use LIKE OR statement using cakephp & mysql

I am new to cakephp and don't know what the syntax is for using LIKE and OR in cakephp with mysql.

Can anyone help me? Thanks..

+7
cakephp
source share
3 answers

Comprehensive search terms from the manual:

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

you can use: for "like"

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

The above query will give you data from table messages, where the author’s name begins with "announcement".

for "OR"

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

The above query will give you data from table messages, where the author’s name begins with "announcement". OR Post starts with "bo".

+6
source share

if you use the where function, then use this: -

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

thanks

0
source share

All Articles