S
S
Svyatoslav Torg2016-10-28 20:08:39
Yii
Svyatoslav Torg, 2016-10-28 20:08:39

How to make data selection by first letter yii2?

Hello, help me, I can’t get into my head anymore (and I don’t know).
You need to select values ​​that start with a letter.
$q = LETTER;
$query = Model::find()->where(['like','name', $q])->orderBy('name ASC')->all();
So he naturally gives me all the meanings where the letter is present. not the first.
Tell me how to do it better?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2016-10-28
@sefkiss

$query = Model::find()->where('name LIKE :q')->addParams(['q'=>$q . '%'])->orderBy('name ASC')->all();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question