So, I'm a newbie and I've searched many places looking for the answer...I think I'm getting close but I just can't seem to figure out my problem. I'm trying to populate my calendar from a database but it's just not working. I've been able to show just one record on each day, and I've been able to show every record on everyday, but I can't seem to marry up the database date with the calendar date and show it correctly on the calendar. See my code below, thanks for all the help!!
<?php
$timestamp = (isset($GET['t'])) ? $GET['t'] : time();
list($month, $day, $year) = explode('/', date('m/d/Y', $timestamp));
$first_day_of_month = date('w', mktime(0,0,0,$month,1,$year));
$total_days = date('t', $timestamp);
// output table header
ob_start();
echo '<table id="calendar" border=0 cellpadding=0 cellspacing=0 class=totalborder align=center>';
echo '<tr id="calendar_header"><td colspan="7" class=calendar_header>';
echo '<a href="' . htmlspecialchars($SERVER['PHP_SELF']) . '?t=' . strtotime('-1 month', $timestamp) . '">«</a> ';
echo date('F', $timestamp) . ' ' . $year;
echo ' <a href="' . htmlspecialchars($SERVER['PHP_SELF']) . '?t=' . strtotime('+1 month', $timestamp) . '">»</a>';
echo '</td></tr>';
echo '<tr class=style3><th>Sunday</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th></tr>';
// output date cells
$current = 1;
while ($current <= $total_days)
{
echo '<tr>';
for ($i = 0; $i < 7; $i++)
{
if (($current == 1 && $i < $first_day_of_month) || ($current > $total_days))
{
echo '<td class=calendar_dates> </td>';
continue;
}
echo '<td class=dayborder>';
echo '<table border=0 cellpadding=2 cellspacing=0>
<tr align=right>
<td class=numberdayC colspan=2>';
echo $current;
echo '</td></tr>';
$query = "SELECT CalendarID, CalDate, CalStation, CalEmp1, CalEmp2, Shift, CalStation2, Sta2Emp1, Sta2Emp2, CalStation3, Sta3Emp1, Sta3Emp2, Sta3StartTime, CalStation4, Sta4Emp1, Sta4Emp2, CalStation5, Sta5Emp1, Sta5Emp2, CalStation6, Sta6Emp1, Sta6Emp2 FROM calendar LEFT JOIN employees ON CalEmp1 = EmpName WHERE Year(CalDate) = " . $year . " AND MONTH(CalDate) = " . $month;
$result = mysql_query($query, $Lifeline) or die(mysql_error());
if (mysql_num_rows($result))
{
while ($row_Calendar = mysql_fetch_array($result))
{
echo '<tr align=center><td class=station>';
echo $row_Calendar['CalStation'];
echo '</td><td class=station>';
echo $row_Calendar['CalStation3'];
echo '</td></tr><tr align=center><td class=small>';
echo $row_Calendar['CalEmp1'];
echo '</td><td class=small>';
echo $row_Calendar['Sta3Emp1'];
echo '</td></tr><tr align=center><td class=small>';
echo $row_Calendar['CalEmp2'];
echo '</td><td class=small>';
echo $row_Calendar['Sta3Emp2'];
echo '</td></tr><tr align=center><td class=station>';
echo $row_Calendar['CalStation2'];
echo '</td><td class=station>';
echo $row_Calendar['CalStation5'];
echo '</td></tr><tr align=center><td class=small>';
echo $row_Calendar['Sta2Emp1'];
echo '</td><td class=small>';
echo $row_Calendar['Sta5Emp1'];
echo '</td></tr><tr align=center><td class=small>';
echo $row_Calendar['Sta2Emp2'];
echo '</td><td class=small>';
echo $row_Calendar['Sta5Emp2'];
echo '</td></tr><tr align=center><td class=station>';
echo $row_Calendar['CalStation4'];
echo '</td><td class=station></td></tr><tr align=center><td class=small>';
echo $row_Calendar['Sta4Emp1'];
echo '</td><td></td></tr><tr align=center><td class=small>';
echo $row_Calendar['Sta4Emp2'];
echo '</td></tr>';
}
}
else
{
echo ' ';
}
mysql_free_result($result);
echo '</table></td>';
$current++;
}
echo '</tr>';
}
echo '</table>';
$GLOBALS['TEMPLATE']['content'] = ob_get_clean();
// assign styles for calendar
$GLOBALS['TEMPLATE']['extra_head'] = '<link rel="stylesheet" type="text/css" href="stylesheet.css"/>';
// display page
include 'template-page.php';
?>