Jump to content

List of scheduled events with mktime problem


tao83

Recommended Posts

I've got a page where it lists events and the dates of the events:

 

September 2009

Name of event

1-2 September 2009

 

Name of event

3-4 September 2009

 

October 2009

Name of event

1-2 October 2009

3-4 October 2009

 

I've used "mktime" PHP function in a "while" loop to move the month up by 1 as it lists the events in each upcoming month.

 

However, I've hit a problem where it just stops listing the events in November 2009.

 

I can't seem to figure out how to increment the month into the next year as well (ie. display December 2009 events and then January 2010 events).

 

<?php
    
    $today = time();//get today's date
    $today = date('Y-m-d', $today);//formate today's date
    $day =  date('d', strtotime($today));//capture day into separate variable
    $month = date('m', strtotime($today));//capture month into separate variable
    $year =  date('Y', strtotime($today));//capture year into separate variable
    $end_of_month = mktime(0, 0, 0, $month+1, 0, $year); //set end of active month
    $end_of_month = date('Y-m-d', $end_of_month);//format end of month date

while (condition) {
        echo "$month $year";
       
        while ($dates=mysql_fetch_array($var)) {
         ......
         echo "event dates";
         }
         $today = mktime(0, 0, 0, $month+1, 1, date('Y'));
         $today = date('Y-m-d', $today); //Once all scheduled dates finished, go onto next month
     $day = date('d', strtotime($today));
     $month = date('m', strtotime($today));
     $year =  date('Y', strtotime($today));
     $end_of_month = mktime(0, 0, 0, $month+1, 0, $year); //reset end of active month
     $end_of_month = date('Y-m-d', $end_of_month);
       
} //end of first loop 

     

 

Basically if anyone can help me correctly increment from December 2009 to January 2010 that would be great!

 

Thanks!

Archived

This topic is now archived and is closed to further replies.

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