title: Get events from mySQL. PHP calendar
body: <p>Im trying to get get a calendarscript to connect to mySQL database. The script is a simple calendarpicker witch I am trying to connect to a database so it can display events. 
  I managed to get the event I have in my database displaying for all days in the month, but I would like it to display as a link only for the day it is set. I would also like to add a function for adding and deleting events, but first thing first. </p>
  
  <p>My database looks like this: </p>
  
  <pre><code>database: calendar
  
  table: calendar_events
  row1: event_title
  row2: event_shortdesc
  row3: event_start
  </code></pre>
  
  <p>This is my entire code for the script, the calendarfunction works fine. </p>
  
  <pre><code>&lt;?php include("includes/header.php")?&gt;
  &lt;?php require_once("includes/db_connection.php")?&gt;
  &lt;?php include("includes/functions.php")?&gt;
  
  &lt;?php
  
  if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("m"); 
  if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); 
  
  $cMonth = $_REQUEST["month"]; 
  $cYear = $_REQUEST["year"]; 
  
  $prev_year = $cYear; 
  $next_year = $cYear; 
  $prev_month = $cMonth-1; 
  $next_month = $cMonth+1; 
  
  if ($prev_month == 0) {
      $prev_month = 12; 
      $prev_year = $cYear-1; 
  }
  
  if ($next_month == 13) {
      $next_month = 1;
      $next_year = $cYear+1;  
  }
  
  $monthNames = Array("Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli",
  "August", "September", "Oktober", "November", "Desember"); 
  
  ?&gt;
  
  &lt;div id="kalendercontainer"&gt;
  
  &lt;a id="prev" href="&lt;?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&amp;year=" . $prev_year; ?&gt;"&gt;Previous&lt;/a&gt;
  
  &lt;span id="monthname"&gt;&lt;?php echo $monthNames[$cMonth-1].' '.$cYear; ?&gt;&lt;/span&gt;
  
  &lt;a id="next" href="&lt;?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&amp;year=" . $next_year; ?&gt;"&gt;Next&lt;/a&gt; 
  
  &lt;table id="kalender"&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;strong&gt;Man&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;&lt;strong&gt;Tir&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;&lt;strong&gt;Ons&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;&lt;strong&gt;Tor&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;&lt;strong&gt;Fre&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;&lt;strong&gt;Lør&lt;/strong&gt;&lt;/td&gt;
  &lt;td&gt;&lt;strong&gt;Søn&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;?php
  $timestamp = mktime(0,0,0,$cMonth,1,$cYear);
  $maxday = date("t",$timestamp);
  $thismonth = getdate ($timestamp);
  $startday = $thismonth['wday']-1;
  
  
  //Get calendar events
  
  $get_cal_events = mysql_query("SELECT * FROM calendar_events WHERE event_start = '{$startday}'"); 
  
  $rows = mysql_fetch_array($get_cal_events); 
  
  $event = $rows['event_title'] . $rows['event_shortdesc']; 
  
  
  //Draw calendar
  
  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&gt;" . ($event) . ($i - $startday + 1) . "&lt;/td&gt;";
      if(($i % 7) == 6 ) echo "&lt;/tr&gt;";
  }                   
  
  ?&gt;
  &lt;/table&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;/div&gt; 
  
  &lt;?php require("includes/footer.php")?&gt;
  </code></pre>