Before i start id like to say ive posted this question as more of a discussion rather than Problem Question.
In my Database i have news posts lets say with 3 columns (Id, title, date). Wher Id and title are self Explanitory the date is stored in mktime() values, in other words the number of seconds passed since 1 January 1970.
Now what i want to do is build an archive link that will display as such
Note the months on which there were no posts are not displayed.
Now as an initial thought i was thinking
Now the above is just something on the top of my head. But if you got any ideas to speed this process up please share.
Will say in advance, date needs to be in mktime format
I would suggest using a database "native" time format, but it works with UNIX timestamps as well.
You can simply do:
SELECT DISTINCT FROM_UNIXTIME(date, '%M %Y') FROM posts;
Optionally with a WHERE
clause limiting the dates to past or future dates. Possibly an ORDER
clause thrown in for good measure. That should be pretty much all that's needed, let the database do as much work as possible.
If you need more formatting options, select the dates with "%Y-%m"
instead and format them in PHP:
date($myCustomFormat, strtotime("$date-01"));