/* this material is provided with ABSOLUTELY NO GUARANTEE. use at your own risk. always test on non-critical systems first. source code developed by Melonfire, http://www.melonfire.com/ copyright 2001, Melonfire. all rights reserved. visit our Web site to find out how you can use this source code and accompanying article on your Web site. */ ?>
// list of names for days and months $days = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); $months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); // number of days in each month $totalDays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // set up some variables to identify the month, date and year to display if(!$currYear) { $currYear = date("Y"); } if(!$currMonth) { $currMonth = date("n"); } if(!$currDay) { $currDay = date("j"); } // if leap year, modify $totaldays array appropriately if (date("L", mktime(0,0,0,$currMonth,1,$currYear))) { $totalDays[2] = 29; } // set up variables to display previous and next months correctly // defaults for previous month $prevMonth = $currMonth-1; $prevYear = $currYear; // if January, decrement year and set month to December if ($prevMonth < 1) { $prevMonth=12; $prevYear--; } // defaults for next month $nextMonth = $currMonth+1; $nextYear = $currYear; // if December, increment year and set month to January if ($nextMonth > 12) { $nextMonth=1; $nextYear++; } // get down to displaying the calendar // find out which day the first of the month falls on $firstDayOfMonth = date("w", mktime(0,0,0,$currMonth,1,$currYear)); include("config.php"); // open a connection to the database $connection = mysql_connect($server, $user, $pass); // formulate the SQL query - same as above $query = "SELECT DISTINCT date from calendar where date >= '" . $currYear . "-" . sprintf("%02d", $currMonth) . "-01' and date <= '" . $currYear . "-" . sprintf("%02d", $currMonth) . "-" . $totalDays[$currMonth] . "'"; // run the query on the database $result = mysql_db_query($db,$query ,$connection); $x=0; $dateList=array(); if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_array($result)) { $dates = explode("-", $row["date"]); $dateList[$x] = $dates[2]; $x++; } } // close connection mysql_close($connection); ?><< | echo $months[$currMonth] . " " . $currYear; ?> | >> | ||||
" . substr($days[$x],0,3) . " | "; } ?>||||||
\n"; } // counter to track the current date $dayCount=1; while ($dayCount <= $totalDays[$currMonth]) { // use this to find out when the 7-day block is complete and display a new row if ($rowCount % 7 == 0) { echo " | ||||||
" . $dayCount. ""; } else { echo " | " . $dayCount . "";
}
for ($y=0; $y | \n";
// increment counters
$dayCount++;
$rowCount++;
}
?>
|||||
this month |