title: Php calendar, to use ajax
body: <p>I have a simple code for a php calendar and I would like to make it use ajax when I go to next or previous month.
  I am not very familiar with ajax nor jquery.
  How can i achieve it? Code:</p>
  
  <pre><code>&lt;?php
  
  $monthNames = Array("January", "February", "March", "April", "May", "June", "July",
  "August", "September", "October", "November", "December");
  
  if (!isset($_GET["m"])) $_GET["m"] = date("n"); 
  if (!isset($_GET["y"])) $_GET["y"] = date("Y");
  
  $currentMonth = $_GET["m"];
  $currentYear = $_GET["y"];
  
  $p_year = $currentYear;
  $n_year = $currentYear;
  $p_month = $currentMonth-1;
  $n_month = $currentMonth+1;
  
  if ($p_month == 0 ) {
      $p_month = 12;
      $p_year = $currentYear - 1;
  }
  
  if ($n_month == 13 ) {
      $n_month = 1;
      $n_year = $currentYear + 1;
  }
  $days=array('1'=&gt;"S",'2'=&gt;"M",'3'=&gt;"T",'4'=&gt;"W",'5'=&gt;"T",'6'=&gt;"F",'7'=&gt;"S");
  
  ?&gt;
  
  &lt;table width="800"&gt;
  &lt;tr align="center"&gt;
  &lt;td bgcolor="#7DC3E3" style="color:#FFFFFF"&gt;
  &lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
  &lt;tr&gt;
  &lt;td width="50%" align="left"&gt;  &lt;a href="&lt;?php echo $_SERVER["PHP_SELF"] . "?m=".$p_month . "&amp;y=" . $p_year; ?&gt;" style="color:#FFFFFF"&gt;Prev&lt;/a&gt;&lt;/td&gt;
  &lt;td width="50%" align="right"&gt;&lt;a href="&lt;?php echo $_SERVER["PHP_SELF"] . "?m=".$n_month . "&amp;y=" . $n_year; ?&gt;" style="color:#FFFFFF"&gt;Next&lt;/a&gt;  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt;
  &lt;table width="100%"  border="1" cellpadding="2" cellspacing="2"&gt;
  &lt;tr align="center"&gt;
  &lt;td colspan="7" bgcolor="#7DC3E3" style="color:#FFFFFF"&gt;&lt;B&gt;&lt;?php echo  $monthNames[$currentMonth-1].' '.$currentYear; ?&gt;&lt;/B&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr &gt;
  &lt;?php for($i=1;$i&lt;=7;$i++){ ?&gt;
  
  &lt;td align="center" height='100' bgcolor="#7DC3E3" style="color:#FFFFFF"&gt;&lt;B&gt;&lt;?php echo $days[$i]; ?&gt;&lt;/B&gt;&lt;/td&gt;
  
  &lt;?php } ?&gt;
  &lt;/tr&gt;
  &lt;?php
  $timestamp = mktime(0,0,0,$currentMonth,1,$currentYear);
  $maxday = date("t",$timestamp);
  $thismonth = getdate ($timestamp);
  $startday = $thismonth['wday'];
  for ($i=0; $i&lt;($maxday+$startday); $i++) {
      if(($i % 7) == 0 ) echo "&lt;tr&gt;";
      if($i &lt; $startday) echo "&lt;td &gt;&lt;/td&gt;";
      else echo "&lt;td align='center'    height='80' valign='middle' bgcolor='#AED5E4' height='20px'&gt;". ($i - $startday + 1) . "&lt;/td&gt;";
      if(($i % 7) == 6 ) echo "&lt;/tr&gt;";
  }
  ?&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I have added the entire code</p>