|
|
Stargeek's PHP ScriptsPlease select a category: |
Search Stargeek's PHP Scripts Database
|
php calendar script This PHP function, hacked from the original calendar script source, at http://www.keithdevens.com/software/php_calendar/source.php this php calendar script returns a color-coded calendar as a string, based on the entries in a mysql database table, correseponding to entries posted in a news table. It is a monthly calendar and entirely real time dynamic php.
<?php function generate_calendar($year, $month, $day_func = NULL, $day_heading_length = 3) { $first_of_month = mktime (0,0,0, $month, 1, $year); static $day_headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $maxdays = date('t', $first_of_month); #number of days in the month $date_info = getdate($first_of_month); #get info about the first day of the month $month = $date_info['mon']; $year = $date_info['year'];
$calendar = "<table class=\"calendar\" width=\"100%\">\n"; $calendar .= "<tr bgcolor=\"#999999\" class=\"news_title\"><th colspan=\"7\" class=\"month\">$date_info[month], $year</th></tr>\n";
$calendar .= '<tr>';
$weekday = $date_info['wday']; #weekday (zero based) of the first day of the month $day = 1; #starting day of the month #take care of the first "empty" days of the month if($weekday > 0){$calendar .= "<td colspan=\"$weekday\"> </td>";}
include('db.php'); $q = "select date from news"; $buff = mysql_query($q, $linkID); while ($bline = mysql_fetch_assoc($buff)) { list($real_date, $junk) = explode(' ', $bline['date']); $b_days[$real_date]++; }
#print the days of the month while ($day <= $maxdays) { if($weekday == 7)#start a new week { $calendar .= "</tr>\n<tr>"; $weekday = 0; } $linkDate = mktime (0,0,0, $month, $day, $year); if("$month $day $year"==date('m d Y')) { $class='today'; } else { $d = date('m/d/Y', $linkDate); if($b_days[$d]) { $class = 'post'; } else { $class = 'empty'; } } $link = "dates.php?date=$linkDate"; $calendar .= "<td class=\"$class\"> <a class=\"hd\" href=\"$link\">$day</a></td>\n"; $day++; $weekday++; } if($weekday != 7) { $calendar .= '<td colspan="' . (7 - $weekday) . '"> </td>'; } return $calendar . "</tr>\n</table>\n"; } generate_calendar(date('Y'), date('m'), $day_func = NULL, $day_heading_length = 3) ?>
|
|