SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Thread: Calendar Help

  1. #1
    Non-Member
    Join Date
    Sep 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calendar Help

    Hi, I'm using the following code, in order to create a basic calendar.
    How do I add a "Next" and "Previous" month button that changes the months upon being clicked?

    Code:
    <link rel="stylesheet" type="text/css" href="Index.css" />
    
    <?php
    $date =time () ;
    $day = date('d', $date);
    $month = date('m', $date) ;
    $year = date('Y', $date) ;//gets the year
    $firstDay = mktime(0,0,0,$month, 1, $year);
    $monthName = date('F', $firstDay);
    
    $firstDayOfWeek = date('D', $firstDay) ;
    
    switch($firstDayOfWeek){
    case "Sun": $spacer = 0; break;
    case "Mon": $spacer = 1; break;
    case "Tue": $spacer = 2; break;
    case "Wed": $spacer = 3; break;
    case "Thu": $spacer = 4; break;
    case "Fri": $spacer = 5; break;
    case "Sat": $spacer = 6; break;
    }
    
    $daysInMonth = cal_days_in_month(0, $month, $year); 
    
    echo '<div id="Container">';
    echo '<div>' . $monthName . " " . $year . '</div>';
    echo '<div>' . Sun . '</div>';
    echo '<div>' . Mon . '</div>';
    echo '<div>' . Tue . '</div>';
    echo '<div>' . Wed . '</div>';
    echo '<div>' . Thu . '</div>';
    echo '<div>' . Fri . '</div>';
    echo '<div>' . Sat . '</div>';
    
    
    $dayCount = 1;
    
    while ( $spacer > 0 )
    {
      $spacer = $spacer-1;
      $dayCount++;
    }
    $dayNumber = 0;
    
    while ( $dayNumber <= $daysInMonth )
    { 
      $dayNumber++;
      $dayCount++;                                                                      
      if ($dayNumber < 10)
      {
        echo "0" . $dayNumber;
      }
      else
      {
        echo $dayNumber;
      }
    
      if ($dayCount > 7)
      {
        $dayCount = 1;
      }
    }
    while ( $dayCount >1 && $dayCount <=7 )
    {
      $dayCount++;
    }
    echo '</div>';
    ?>
    TheBIGCube
    Last edited by TheBIGcube; Sep 23, 2007 at 01:31.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •