Jump to content

How to get PHP to auto-create Months/Years


Call-911

Recommended Posts

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!

Link to comment
Share on other sites

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...

 

 

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.