Answer the question
In order to leave comments, you need to log in
How to get last 10 records in active record?
$latests = Project::find()->where(['status' => 1])->limit(10)->all();
I do this, but it pulls out from the end of the base, that is, the first 10, but the last 10 are needed.
Answer the question
In order to leave comments, you need to log in
all data in the database is stored in an unordered form, so what is the "last 10" is known only to you and God. To solve the problem, you need to determine by what attribute the latest records are determined and sort the data accordingly, according to this attribute, for example:
$latests = Project::find()->where(['status' => 1])->orderBy(['id' => SORT_DESC])->limit(10)->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question