php中博客日历实现代码
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-02 10:24:31 浏览: 评论:0
分享一款php中博客日历实现代码,里面有一句是查询数据库的这个很简单,只要你修改一下字段名与你数据库相同就行了,实例代码如下:
- 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 .= '<tr align="center" class="smalltxt">';
- 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 .= '<td>'.$curtd.'</td>';
- } else {
- $cal .= '<td><a href="blog.php?uid='.$uid.'&starttime='.$blogs[$cur]['dateline'].'&endtime='.($blogs[$cur]['dateline'] + 86400).'" title=" '.$blogs[$cur]['num'].' "><b>'.$cur.'</b></a></td>';
- }
- }
- $cal .= '';
- }
- return $cal;
- }
Tags: php日历 php博客
相关文章
- ·php简单日历函数(2021-06-23)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)