Tuesday 15 September 2015

php - Best way to count and group blog-like results -


We have a database of news posts on our site that contains some 3,000 lines (for each post, dating back to 2001) . Each has a Unix timestamp which shows the date of the post.

I have to be an archive page, which summarizes how many posts of that month, depending on the year, then the month

  January 2011 (13 posts) 25 posts) 2012 March (30 terms)   

etc.

What is the most effective way to do this? I had a messy code before it would ask the database for two months for two months (year, month) and count how many posts were made. It was incredibly slow, incredibly slow.

How to group data and any tips to avoid killing the database for every single month, it is best controlled with a table in the database to keep the data on a monthly basis < /p>

You can have a simple table with 3 columns. year | Month | On a daily basis, you calculate the number of posts of that month for a simple aggregate query (using a filter) and calculate it to update the table above

This fast and Will be clear

No comments:

Post a Comment