Hey guys,
Been messing with the below script(courtesy of macromedia.com)
I want to select records from a database table based on whatever day of the month the user clicks on.
How is this done? Here is the calendar script - the user clicks on a date and should be taken to a page that displays the database records based on that date.
<?php
function build_calendar($month,$year,$day)
{
$daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa');
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
$noDays = date('t',$firstDayOfMonth);
$dateComponents = getdate($firstDayOfMonth);
$dayOfWeek = $dateComponents['wday'];
$monthName = date('F',mktime(0,0,0,$month,1,$year));
// compute the next and previous month
if($month == 1)
{
$mn=12;
$yn=$year-1;
}
else
{
$mn=$month-1;
$yn=$year;
}
if($month == 12)
{
$mn2=1;
$yn2=$year+1;
}
else
{
$mn2=$month+1;
$yn2=$year;
}
// html table
$calendar = "<table>";
$calendar .= "<tr><td><a href=mac_calendar.php?m=$mn&y=$yn&d=$day><</a></td>";
$calendar .="<td colspan=5 align=center>$monthName, $year</td>";
$calendar .="<td><a href=mac_calendar.php?m=$mn2&y=$yn2&d=$day>></a></td></tr>";
$calendar .="<tr>";
// display days of week
foreach($daysOfWeek as $day)
{
$calendar .= "<td>$day</td>";
}
$calendar .= "</tr>";
$calendar .= "<tr>";
// variable to move through days of month
$currentDay = 1;
// ensure table has 7 cols
if ($dayOfWeek > 0)
{
$calendar .= "<td colspan='$dayOfWeek'> </td>";
}
// generate days of month
while ($currentDay <= $noDays)
{
if ($dayOfWeek == 7)
{
$dayOfWeek = 0;
$calendar .= "</tr><tr>";
}
$calendar .= "<td><a href='#'>$currentDay</a></td>";
$currentDay++;
$dayOfWeek++;
}
// check last day of month is last day of wk
if ($dayOfWeek != 7)
{
$remainingDays = 7 - $dayOfWeek;
$calendar .= "<td colspan='$remainingDays'> </td>";
}
$calendar .= "</table>";
return $calendar;
} // end function
if (isset($_GET['m']) && isset($_GET['y']) && isset($_GET['d'])){
$month = $_GET['m'];
$year = $_GET['y'];
$day = $_GET['d'];
} else {
$dateComponents = getdate();
$month = $dateComponents['mon'];
$year = $dateComponents['year'];
$day = $dateComponents['mday'];
}
echo build_calendar($month,$year,$day);
?>
My database table uses type date. So guess query should be like this...
$query = "SELECT * from archive WHERE file_date = $date";
Thanks,
Kevin.