title: php calendar that connects to database mysql for events
body: <p>So i have code for a very simple calendar, however I can't figure out how to query mysql database to find any events for each day of the month. I know how to query the database for that information, but i dont know where i would put it in the code of creating a calendar or how to structure it or anything. ive looked at many codes of php calendars and for each code i havent been able to get data from my database, i just have no idea how to do it. any help is grateful, thanks.
  calendar code editted to include db stuff:</p>
  
  <pre><code>include ("connection.php"); 
  
  $date =time (); 
  $day = date('d', $date); 
  $month = date('m', $date); 
  $month = $month + "02";
  $year = date('Y', $date); 
  $years = substr($year, 2, 2);
  
  $first_day = mktime(0,0,0,$month, 1, $year); 
  $title = date('F', $first_day); 
  $day_of_week = date('D', $first_day); 
  switch($day_of_week){ 
      case "Sun": $blank = 0; break; 
      case "Mon": $blank = 1; break; 
      case "Tue": $blank = 2; break; 
      case "Wed": $blank = 3; break; 
      case "Thu": $blank = 4; break; 
      case "Fri": $blank = 5; break; 
      case "Sat": $blank = 6; break; 
  }
  
  $days_in_month = cal_days_in_month(0, $month, $year);
  echo "&lt;table border=1 width=294&gt;";
  echo "&lt;tr&gt;&lt;th colspan=7&gt; $title $year &lt;/th&gt;&lt;/tr&gt;";
  echo "&lt;tr&gt;&lt;td width=42&gt;S&lt;/td&gt;&lt;td width=42&gt;M&lt;/td&gt;&lt;td 
  width=42&gt;T&lt;/td&gt;&lt;td width=42&gt;W&lt;/td&gt;&lt;td width=42&gt;T&lt;/td&gt;&lt;td 
  width=42&gt;F&lt;/td&gt;&lt;td width=42&gt;S&lt;/td&gt;&lt;/tr&gt;";
  $day_count = 1;
  echo "&lt;tr&gt;";
  
  while ( $blank &gt; 0 ) 
  { 
      echo "&lt;td&gt;&lt;/td&gt;"; 
      $blank = $blank-1; 
      $day_count++;
  } 
  $day_num = 1;
   while ( $day_num &lt;= $days_in_month ) 
  { 
  
  echo "&lt;td&gt; $day_num &lt;br/&gt;";
  
  
  $result = mysql_query("SELECT time, length FROM hire WHERE day = '$day_num' and month =    '$month' and year = '$years'") or die ('Error: '.mysql_error ());
  </code></pre>
  
  <p>while ($row = mysql_fetch_array($result)){</p>
  
  <pre><code>$time = $row['time'];
  $length = $row['length'];
  
  }
  
  if (isset($time) and (isset($length))) {
   echo "Time: " . $time . "&lt;br/&gt; Length: " . $length . "&lt;br/&gt;";
  }
  
  "&lt;/td&gt;";
  
  
  
      $day_num++; 
      $day_count++;
          if ($day_count &gt; 7)
          {
          echo "&lt;/tr&gt;&lt;tr&gt;";
          $day_count = 1;
          }
  
  } 
  
  while ( $day_count &gt;1 &amp;&amp; $day_count &lt;=7 ) 
  { 
      echo "&lt;td&gt; &lt;/td&gt;"; 
      $day_count++; 
  } 
  
  echo "&lt;/tr&gt;&lt;/table&gt;"; 
  </code></pre>