Looping through months

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fluidbyte
Forum Commoner
Posts: 30
Joined: Tue May 27, 2008 2:07 pm

Looping through months

Post by fluidbyte »

I'm creating an article listing system, and just like every blog/news site out there I would like to create an archive by month/year.

I've got the starting month (##) and starting year (####) (and of course I know the current month (##) and current year(####)), I just can't figure out how to loop out the months in between. I know someone out there has to know how to do this...
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Looping through months

Post by josh »

Code: Select all

 
for( $offset = 1; $offset <= 12; $offset++ )
{
  $current_month++;
  if( $current_month == 13 )
  {
     $current_month=1;
     $curent_year++;
  }
}
 
something like that?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Looping through months

Post by VladSun »

Where does the data come from? From DB?
What do you mean by "create an archive" exaclty?
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply