Home > php教程 > php手册 > 博客中添加日历的php代码

博客中添加日历的php代码

WBOY
Release: 2016-06-13 09:28:39
Original
1051 people have browsed it

博客中添加日历的php代码

  想不想在你得博客中添加日历啊?blue1000在这里跟大家简洁的分享一款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

  $cal .= '';

  for($col = 0; $col

  $cur = $row * 7 + $col - $skip + 1;

  $curtd = $row * 7 + $col $dim ? ' ' : $cur;

  if(!isset($blogs[$cur])) {

  $cal .= ''.$curtd.'';

  } else {

  $cal .= ''.$cur.'';

  }

  }

  $cal .= '';

  }

  return $cal;

  }

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template