tags:

views:

27

answers:

1

Hey guys.

I have a question: I now have a sort array where I have all the news that I fetch from the database. But now ALL are shown. What I want are the news from the last 3 months and these news grouped by month.

september .........

News 1, News 2 News 3, News 4

august ....... . . .

Any ideas?

A: 

Your ORM library should have some mechanism for restricting a query with a criteria. You'll need to use that to limit the number of news stories that are returned.

There are two basic options:

  1. Query for news stories from 2 months ago, then query for news stories from 1 month ago, and finally query for news stories from this month.
  2. Query for all news stories in the last 3 months. Then iterate through the results and group them into the buckets you wish to display. It may be more efficient to ask the ORM library to sort the results so that you know you'll see one whole month of news at a time.
Jeremy Stein