With your code you are asking to build a criteria that matches records that have:
published = "true"
AND city LIKE %{$_GET[‘city’]}%
OR type LIKE %{$_GET[‘word’]}%
OR category LIKE %{$_GET[‘word’]}%
You’ll agree with me you get exactly what you coded.
But I believe you want this:
published = "true"
AND city LIKE %{$_GET[‘city’]}%
AND [color="#FF0000"]([/color]type LIKE %{$_GET[‘word’]}% OR category LIKE %{$_GET[‘word’]}%[color="#FF0000"])[/color]
Right?
So you need to use CDbCriteria::mergeWith():
$criteria = new CDbCriteria(array(
'condition'=>'published="true"'
));
if (isset($_GET['city']) || isset($_GET['word'])) {
if (!empty($_GET['city'])) {
$criteria->addSearchCondition('city', $_GET['city'], true, 'AND'); /* 'AND' is the default value for $operator, so needless here */
}
if (!empty($_GET['word'])) {
$criteria2 = new CDbCriteria;
$criteria2->addSearchCondition('type', $_GET['word'], true);
$criteria2->addSearchCondition('category', $_GET['word'], true, 'OR');
$criteria->mergeWith($criteria2);
}
}
PS Please format your code with, at least, the <> button on the post’s textarea toolbar (you can edit your original post to do so)