Using CAutoComplete with Database

Hello,

I've been struggling with this all day and have given up and asking for some help.  The example application of CAutoComplete from this post works fine when passing it the array.

http://www.yiiframew…php?topic=651.0

But, when I try to pass it data from a database, I get nothing.  I'm thinking something is not formated correctly in the array.

Here is my code and I would appreciate any help.

public function actionSuggest()


{


	if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))


	{


		$results=$this->getApiSuggestions($_GET['q']);


		echo implode("n",$results);


	}


}





protected function getApiSuggestions($search)


{


	$search=strtolower($search);


	    


  	$connection=Yii::app()->db;


	$sql ="SELECT * FROM auto_comp";  //will get everything for now


	$command=$connection->createCommand($sql);


	$result = $command->query($sql); 


	$results = $result->readAll(); 


	


	


	


	


	//$results= array('waterloo', 'Waterford', 'Guelph,ON,Ward','Waterloo,ON,Lakeshore');  //it works if this array is passed


	


	


	//$results=array();


	foreach($results as $keyword)


	{


		


		if(strpos(strtolower($keyword),$search)!==false)


			$results[]=$keyword;


	}


	return $results;

Try directly accessing the 'suggest' action in your browser (remove that isAjaxRequest temporarily)?

Thanks Qiang, just figured it out.  I was accessing the array at the wrong level. 

R