Like And Or In Query Builder

if (Yii::app()->request->isAjaxRequest && isset($_GET['term'])&&($keyword=trim($_GET['term']))!=='')


$models = Yii::app()->db->createCommand()->selectDistinct('district')


				 ->where('or like', "district :keyword property :keyword",array(':keyword'=>"$keyword%"))

				 ->order('district asc')




				foreach($models as $model) {

					$suggest[] = array(





echo CJSON::encode($suggest);


I’m gettin error in autocomplete field. How to make this query: select DISTINCT district from unitlistings WHERE disitrct LIKE ‘%keyword%’ or property LIKE ‘%keyword%’

Just write your condition inside where()… like:

where("district like :keyword or property like :keyword",array(':keyword'=>"%$keyword%"))

I was getting duplicate result in autocomplete field. using selectDistinct(‘district’) now gives empty result