There is a search form, the first and second input I use a widget from kartik kartik\typeahead\Typeahead; .

When I try to find a tow truck, then I have a dubbing, I would like to get rid of it.

The example itself looks like:

enter image description here

This is a table where users retain their specialty.

enter image description here

 controller`public function actionCategoryList($q = null) { $query = new Query(); $query->select('title') ->from('profile_has_category') ->where('title LIKE "%' . $q . '%"') ->orderBy('title'); $command = $query->createCommand(); $data = $command->queryAll(); $out = []; foreach ($data as $d) { $out[] = ['value' => $d['title']]; } echo Json::encode($out); } 

View

 Typeahead::widget([ 'name' => 'Search[category]', 'options' => ['placeholder' => 'Искать специальности ...'], 'pluginOptions' => ['highlight' => true], 'class' => 'search-input-spec', 'dataset' => [ [ 'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')", 'display' => 'value', //'prefetch' => $asset->baseUrl . '/samples/countries.json', 'remote' => [ 'url' => Url::to(['search/category-list']) . '?q=%QUERY', 'wildcard' => '%QUERY' ] ] ] ]); 

    1 answer 1

    What you choose, it gives. Most likely, you need to select DISTINCT (used to return only different values ​​from the table):

     $query->select('title') ->distinct() ->from('profile_has_category') ... ... // и т.д.