Call-911 Posted February 7, 2011 Share Posted February 7, 2011 Hello All, I have a News database in which articles are entered in. Right now all the stories are being display in one big page with every story on it. What I would like to do is to create an "archive" in which it automatically organizes the stories by their date. For example. 2011 February January 2010 December November October September etc... etc... I have a datetime field for the database, and I know how to do this all manually, but I can't figure out how to make it automatically add a month each month. It would be too much maintanence to have to update this every month. I also don't know what this would be called, so I don't even know what to search for. I've tried blog and news, but doesn't seem to be what I want. Any help would be appreciated! Quote Link to comment Share on other sites More sharing options...
zenlord Posted February 7, 2011 Share Posted February 7, 2011 You don't need to change anything in the dbase/backend. Just change your view to only display news from the period you want (f.e. only news from feb 2011). Quote Link to comment Share on other sites More sharing options...
Call-911 Posted February 7, 2011 Author Share Posted February 7, 2011 zenlord, I can do that manually and manually link up the months to something like stories.php?month=january But how can I have PHP automatically create a new month every month. ie, right now it would say 2011 February Janaury 2010 December November etc. etc. But then on March 1 this year automatically add in march so it goes to 2011 March February January etc... Quote Link to comment Share on other sites More sharing options...
zenlord Posted February 7, 2011 Share Posted February 7, 2011 using a for-loop or foreach-loop? Make an array with the all the names of the months in it and embed that array inside a for-loop for an array that starts at this year and then counts down 5 times, f.e. or using date-and-time-functions: output this month and then subtract a month for 60 times (5 years * 12 months). Many ways to do this. pick one Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 7, 2011 Share Posted February 7, 2011 You can execute a select query to get the distinct year/month-name values based on your datetime values. Should work - SELECT DISTINCT YEAR(datetime_column) as yr, MONTHNAME(datetime_column) as mn FROM your_table ORDER BY datetime_column DESC Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.