Answer the question
In order to leave comments, you need to log in
Activerecord limit selection of news by widget?
Good afternoon.
Lack of experience in writing database queries.
There is a news site on (yii2) where you need to display a certain number of news for each widget.
You need to select all entries where widget = 2(NEWS_CARD_WIDGET) and category = 1($categoryId), sort them by date so that the latest entries are at the top and take the first 5 items from this.
What now:
News::find()->published()->where(['widget' => News::NEWS_CARD_WIDGET, 'category' => $categoryId])->orderBy(['created_at' => SORT_DESC])->limit(5);
Answer the question
In order to leave comments, you need to log in
- var data = { "items" : [ { "articles": [ { "title": "Заголовок 2", }, { "title": "Заголовок 1" } ] } ] };
p= data.items[0].articles[0].title
Of course, I may be very wrong, but is it acceptable to set the same keys in JSON?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question