Answer the question
In order to leave comments, you need to log in
How to select records starting with a number in yii2?
You need to select records by the first character of a letter or number.
In the case of letters, everything is simple. is selected one by one by the expression:
Model::find()->where(['like', 'name', $letter . '%', false, 'status' => 1])->andWhere(['status' => 1])->all();
Answer the question
In order to leave comments, you need to log in
Make a separate field for the letter index, and when creating, save the first character of the name in the index with the model. And then choose according to it, and you will not need to use LIKE queries, which are not the fastest, especially if you need to display all records from the database that begin with the desired letter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question