title: PHP Calendar - Hide Days Previous To Today
body: <p>I have a calendar on my website using PHP/HTML and it works fine except that for some reason it is displaying the last 5 days previous to today's date when ideally I want them to be hidden. Here is my PHP &amp; CSS code:</p>
  
  <pre><code>.calendarHeader{
      text-align: center;
      text-decoration: underline;
      color: #303030;
  }
  .calendarDates{
      margin: 30px auto auto auto;
      width: 280px;
  }
  .calendar{
      margin: 10px auto auto auto;
      width: 280px;
  }
  .calendarCell{
      float: left;
      width: 40px;
      color: #707070;
      text-align: center;
      padding: 5px 0px 5px 0px;
  }
  .calendarCell:hover{
      color: #000000;
  }
  .calendarBlank{
      color: #E9EAEB;
      cursor: default;
  }
  .calendarBlank:hover{
      color: #FFFFFF;
  }
  .calendarToday{
      color: #BC3415;
      font-weight: bold;
  }
  
  &lt;?php
  $today = date("d"); // Current day
  $month = date("m"); // Current month
  $displaymonth = date("F");
  $year = date("Y"); // Current year
  $days = cal_days_in_month(CAL_GREGORIAN,$month,$year); // Days in current month
  
  $lastmonth = date("t", mktime(0,0,0,$month-1,1,$year)); // Days in previous month
  
  $start = date("N", mktime(0,0,0,$month,1,$year)); // Starting day of current month
  $finish = date("N", mktime(0,0,0,$month,$days,$year)); // Finishing day of  current month
  $laststart = $start - 1; // Days of previous month in calander
  
  $counter = 1;
  $nextMonthCounter = 1;
  
  echo '
  
      &lt;div class="calendarHeader"&gt;&lt;strong&gt;'.$displaymonth.' '.$year.'&lt;/strong&gt;&lt;/div&gt;
      &lt;div class="calendarDates"&gt;
          &lt;div class="calendarCell"&gt;&lt;b&gt;M&lt;/b&gt;&lt;/div&gt;
          &lt;div class="calendarCell"&gt;&lt;b&gt;T&lt;/b&gt;&lt;/div&gt;
          &lt;div class="calendarCell"&gt;&lt;b&gt;W&lt;/b&gt;&lt;/div&gt;
          &lt;div class="calendarCell"&gt;&lt;b&gt;T&lt;/b&gt;&lt;/div&gt;
          &lt;div class="calendarCell"&gt;&lt;b&gt;F&lt;/b&gt;&lt;/div&gt;
          &lt;div class="calendarCell"&gt;&lt;b&gt;S&lt;/b&gt;&lt;/div&gt;
          &lt;div class="calendarCell"&gt;&lt;b&gt;S&lt;/b&gt;&lt;/div&gt;
  
          &lt;div class="clearLeft"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="calendar"&gt;
      ';
  
      if($start &gt; 5){ $rows = 6; }else {$rows = 5; }
  
      for($i = 1; $i &lt;= $rows; $i++){
          for($x = 1; $x &lt;= 7; $x++){             
  
              if(($counter - $start) &lt; 0){
                  $date = (($lastmonth - $laststart) + $counter);
                  $class = 'calendarBlank';
              }else if(($counter - $start) &gt;= $days){
                  $date = ($nextMonthCounter);
                  $nextMonthCounter++;
  
                  $class = 'calendarBlank';
  
              }else if($counter &lt;= $today){
                  $date = ($counter - $start + 1);
                  $class = 'calendarBlank';
              }else {
                  $date = ($counter - $start + 1);
                  if($today == $counter - $start + 1){
                      $class = 'calendarToday';
                  }
              }                                       
  
              echo '&lt;a href="events.php" target="_parent"&gt;&lt;div class="calendarCell '.$class.'"&gt;'.$date.'&lt;/div&gt;&lt;/a&gt;';
  
              $counter++;
              $class = '';
          }
      }
  
      echo '
      &lt;div class="clearLeft"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="calendarNavigation"&gt;
          &lt;div class="floatLeft"&gt;&amp;laquo; &lt;a href="calendar.php?month=-1"&gt;Previous Month&lt;/a&gt;&lt;/div&gt;
          &lt;div class="floatRight"&gt;&lt;a href="calendar.php?month=+1"&gt;Next Month&lt;/a&gt; &amp;raquo;&lt;/div&gt;
          &lt;div class="clearBoth"&gt;&lt;/div&gt;
      &lt;/div&gt;
  ';
  ?&gt;
  </code></pre>
  
  <p>Can anyone tell me how to block out everything previous to today's date?</p>
  
  <p>Also, as you can see, I'd like to have a next &amp; previous months navigation but I don't know how to get the navigation to refresh the php script with the relevant month information. Any help on this would be hugely appreciated too</p>