How to display categories that have records?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
16 views
Hello !
I have two signs in the database, a List of Categories and Records. The table Entries store the id of the selected Category when you publish.
Faced with this challenge, I want to display on the list page, where such information:
Category(if it has at least one record), and under it the last 5 records.
And so to each other.

Tell me how this in Yii2 to organize.
Thanks in advance.
by | 16 views

1 Answer

0 like 0 dislike
SELECT c.category_id, COUNT(r.record_id) AS records FROM category AS c LEFT JOIN records AS r USING(record_id) GROUP BY c.record_id HAVING records > 5
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Apr 25, 2019 by dmitrylee
110,608 questions
257,187 answers
0 comments
40,796 users