Answer the question
In order to leave comments, you need to log in
How to pull data from the database, according to the IDs in the array, using activeRecord in yii2?
Something I'm stupid, gentlemen, I got lost in three pines, as they say.
There is a table with posts. I need to get out of it the posts of the people I follow.
The IDs of these people are in the array, for example $ifollow.
Posts should be sorted by date and taken in 20 pieces by Ajax.
Those. the request is like this:
SELECT *
FROM `sel_posts`
WHERE `login_id` = 22 OR 23 OR 24 ... (все значения массива по сути)
ORDER BY `datetime` DESC
LIMIT 0 , 20
Answer the question
In order to leave comments, you need to log in
$ids = [1, 2, 3, 4, 5];
$items = SelPost::find()->where(['login_id' => $ids])->order('datetime desc')->limit(20)->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question