Difference between #3 and #4 of
How to create a criteria condition for a multiple value text search i.e a "LIKE IN"

Revision #4 has been created by toph on Aug 3, 2014, 5:06:27 PM with the memo:

Added alternative solution using `mergeWith`
« previous (#3) next (#5) »

Changes

Title unchanged

How to create a criteria condition for a multiple value text search i.e a "LIKE IN"

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

search, like, in, cdbcriteria

Content changed

[...]
[sql]

... WHERE ((((name LIKE '%ABC%') OR (name LIKE '%RET%')) OR (name LIKE '%Anything else%')) AND (type=1)) ...
~~~

For cases where this isn't possible,
another solution is to create another CDbCriteria instance to handle this specific condition and use CDbCriteria::addCondition() to[CDbCriteria::mergeWith()](http://www.yiiframework.com/doc/api/1.1/CDbCriteria#mergeWith-detail "CDbCriteria::mergeWith()") to combine the two CDbCriteria instances as follows (thanks to Peter Jk's comment).
 
 
 
```php 
$c1=new CDbCriteria; // original criteria
 
$c2=new CDbCriteria; // criteria for handling our search values
 
 
foreach($search_values as $txt){ 
 
$c2->compare('name',$txt,true,'OR');
 
}
 
 
$c1->mergeWith($c2); // Merge $c2 into $c1
 
 
```
 
 
You can also use [CDbCriteria::addCondition()](http://www.yiiframework.com/doc/api/1.1/CDbCriteria#addCondition-detail "CDbCriteria::addCondition()") to manually
add it to the original criteria as follows.:
[...]
```

 
 
0 0
5 followers
Viewed: 54 437 times
Version: 1.1
Category: How-tos
Written by: toph
Last updated by: toph
Created on: Jan 20, 2014
Last updated: 7 years ago
Update Article

Revisions

View all history