Do you want to add a calendar to your blog? blue1000 here with you to share a simple PHP blog calendar Implementation Code, there is a need for a friend to refer to, there is a query database this is very simple, you just modify the field name and your database the same line.
The code is as follows:
function calendarnew ($starttime = 0) {
Global $db, $tablepre, $timestamp, $site _timeoffset, $site _dateformat, $curtime;
$starttime = $starttime? $starttime: $timestamp;
$curtime = Gmdate ($site _dateformat, $starttime + $timeoffset * 3600);
$pendtime = $starttime-(gmdate (' J ', $starttime + $timeoffset * 3600)-1) * 86400-($starttime + $timeoffset * 3600)% 86400;
$pstarttime = $pendtime-gmdate (' t ', $pendtime + $timeoffset * 3600-1) * 86400;
$nstarttime = $pendtime + gmdate (' t ', $pendtime + $timeoffset * 3600 + 1) * 86400;
$nendtime = $nstarttime + gmdate (' t ', $nstarttime + $timeoffset * 3600 + 1) * 86400;
List ($skip, $dim) = Explode ('-', gmdate (' w-t ', $pendtime + $timeoffset * 3600 + 1));
$rows = Ceil (($skip + $dim)/7);
$blogs = Array ();
$query = $db->query ("Select Dateline from {$tablepre}vitaitems WHERE dateline BETWEEN ' $pendtime ' and ' $nstarttime '");
while ($blog = $db->fetch_array ($query)) {
$day = gmdate (' j ', $blog [' Dateline '] + $timeoffset * 3600);
!isset ($blogs [$day])? $blogs [$day] = array (' num ' => 1, ' Dateline ' => $blog [' Dateline ']-$blog [' Dateline ']% 86400): $blogs [$day] [' num ']]+ +;
}
$cal = ';
for ($row = 0; $row < $rows; $row + +) {
$cal. = ';
for ($col = 0; $col < 7; $col + +) {
$cur = $row * 7 + $col-$skip + 1;
$CURTD = $row * 7 + $col < $skip | | $cur > $dim? ': $cur;
if (!isset ($blogs [$cur])) {
$cal. = '. $curtd.
} else {
$cal. = '. $cur.
}
}
$cal. = ';
}
return $cal;
}