Auto Complete

Hi y’all,

I know how to perform auto complete, but this is only with pre defined arrays . Could any of you folks show me how this is done from a database.

I have tried but it’s just not going through

echo "<p>Picking from a database</p>";

$sql_a = Yii::app()->db->createCommand()

-&gt;select('first_name, last_name')


-&gt;from('tbl_people')


-&gt;queryRow();

//$query_a = mysql_fetch_array($sql_a);

$this->widget(‘zii.widgets.jui.CJuiAutoComplete’, array(

'name'=&gt;'firstNAmes',


'source'=&gt;&#036;sql_a[&quot;first_name&quot;],


// additional javascript options for the autocomplete plugin


'options'=&gt;array(


    'minLength'=&gt;'2',


),


'htmlOptions'=&gt;array(


    'style'=&gt;'height:20px;'


),

));

I’m quite sure there is something fundamentally wrong i must be doing; but what else can i say …

thanks in advance

I think you’d have more luck with:




$sql_a = Yii::app()->db->createCommand()

        ->select('first_name')

        ->from('tbl_people')

        ->queryColumn();


$this->widget('zii.widgets.jui.CJuiAutoComplete', array(

    'name'=>'firstNames',

    'source'=>$sql_a,

    // additional javascript options for the autocomplete plugin

    'options'=>array(

        'minLength'=>'2',

    ),

    'htmlOptions'=>array(

        'style'=>'height:20px;'

    ),

));



Note the changes to both the query and the widget’s source attribute.

@Keith

Mate, thanks a million. That certainly did the trick