We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Post counter

Hello,

I have to make forum endpoint where I need to count posts of each thred and return one thred with highest number of posts. In my database table I have post table with id of thred (id of threed where post belong). How to count posts of each thred and then return thred with highest number of posts.

Thanks



93.7k
Accepted
answer

You can make a group by query on posts table. Counting posts.id, while grouping by thread_id. Also you can add order by postsCounter DESC and LIMIT 1 to get only thread with highest posts. Or LIMIT 10 for top 10 most commented threads e.t.c...



23.6k

Thanks friend, I id it with grouping results and order it with right way .. thx again

edited Jul '16

Glad you solved it @Armin, can you perhaps paste your code/query here in case some other forum member needs it in future?

Thanks.