title: php calendar previous button continuously incrementing
body: <p>"Thank you I have already solved my problem I think this one work"</p>
  
  <p>I have a code that display only mondays of the month.</p>
  
  <p>The next button is not calculating well. </p>
  
  <p>Supposed to be it well end on 12(Month).</p>
  
  <p>But it continuously adding the month.</p>
  
  <p>This is my PHP code.</p>
  
  <pre><code>&lt;?php
  
  
  $current_month = date("n");
  $month = ($_GET['m']) ? $_GET['m'] : date("n");
  
  
  $previous_month = ($month - 1);
  
  $next_month = ($month + 1);
  
  $year = ($_GET['y']) ? $_GET['y'] : date("Y");
  $previous_year = $year;
  
  if($month == 0)
  {
    $month = 12;
    $year--;
  }
  
  if($month == 13)
  {
    $month = 1;
    $year++;
  }
  
  if($previous_month == 0)
  {
    $previous_month = 12;
    $previous_year--;
  }
  
  $startDate  = $year."-".$month."-01";
  $endDate = $year."-".$month."-31";
  
  
  
  $endDate = strtotime($endDate);
  echo("&lt;form name = 'formCalendar' id = 'formCalendar' action = 'calendar1.php?' method = 'get'&gt;");
  echo '&lt;table border=1&gt;';
  echo '&lt;tr&gt;';
  for($i = strtotime('Monday', strtotime($startDate)); $i &lt;= $endDate; $i = strtotime('+1 week', $i))
  
      echo '&lt;td&gt;'.date('d-M-y', $i).'&lt;/td&gt;';   
  
  echo '&lt;/tr&gt;';   
  echo("        &lt;/select&gt;");
  echo("        &lt;input type = 'button' name = 'prev' value = '&lt;&lt;' onclick = 'location=\"calendar1.php?m={$previous_month}&amp;y={$previous_year}\"'/&gt;");
  echo("        &lt;input type = 'button' name = 'next' value = '&gt;&gt;' onclick = 'location=\"calendar1.php?m=". ($month + 1)."&amp;y={$year}\"'/&gt;");
  echo("  &lt;/table&gt;");
  echo("&lt;form&gt;");
  
  ?&gt;
  </code></pre>
  
  <p>Pls help fix the problem.</p>