Reputation: 11
I want to do free search on 5 columns in my view. I have following 5 columns 1. Category 2. Type 3. Reference 4. Url
and now if users enter this data CATEGORY == file , TYPE == technical , REFERENCE == umair , URL == files/umair.jpg
I want to search all rows from databse in which there exists a cateogry "file" in any row of column one and type " technical" in any row of column and so on i am trying to Apply "OR" condition but its giving errors.
Here is my query :
$this->set('Grades', $this->Grade->find('all', array('conditions'=>array('Grade.category'=>$category,'Grade.type'=>$type,'Grade.reference'=>$reference,'Grade.url'=>$url))));
THis query is returning Just one row which contains having category == file AND type== technical and reference == umair and url == files/umair.jpg but i want it should return all rows where category == file OR type == technical OR reference == umair OR url == files/umair.jpg
Upvotes: 0
Views: 23
Reputation: 1533
You need to use OR as the condition type. Cake will use AND by default
$conditions = array(
'OR' => array(
'Grade.category'=>$category,
'Grade.type'=>$type,
'Grade.reference'=>$reference,
'Grade.url'=>$url
)
)
Upvotes: 4