Answer the question
In order to leave comments, you need to log in
How to correctly select rows from the database by the id collection in Yii2?
Good afternoon!
1) What is the most correct way in Yii2 (QB) to extract all rows by id from the database. At the same time, I have a list of id (s), it is stored in an array, like
$arr = [
1, 4, 5
];
Answer the question
In order to leave comments, you need to log in
Goodnight.
You can clean up the array from duplicate data array_unique
Well, in yii2 itself, create a query to fetch data from the database, taking into account the values of your array.
Something like this request
// возвращает покупателей с идентификаторами 100, 101, 123 и 124
// SELECT * FROM `customer` WHERE `id` IN (100, 101, 123, 124)
$customers = Customer::findAll([100, 101, 123, 124]); // передайте сюда свой очищенный от повторений массив
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question