A Problem

April 30, 2006
You know how at job interviews you are sometimes asked to discuss a problem and how you solved it? I just got a great answer tonight: I was building a function that would display all the posts I've made separated by month and year. My first inclination was to ask the DB for each post, one at a time, then I create an array for each month and place the posts in their proper spot within that array. But then I thought about what woud happen if there were no new posts for a month. Users might get confused if they are looking at the posts from july, click previous and see may instead of the expected June. They might think there was some sort of program error. So I changed how I was treating the problem. I decided to figure out when were the first and last posts made, then create a list of every month in-between. This way also has the advantage that I can easily limit the posts to those from the month in question using a sql query instead of having to sort the results later.