php文章管理系统教程案例,PHP经典项目案例-(1)博客管理系统3

PHP经典项目案例-(一)博客管理系统3

本篇给出首页左侧导航栏及右部公告区的实现。

六、左侧导航栏:

1、日历:

这里单独一个php文件,在显示日历的那个地方直接引用该文件即可:

cale.php

"一月", "02"=>"二月", "03"=>"三月", "04"=>"四月", "05"=>"五月", "06"=>"六月", "07"=>"七月", "08"=>"八月", "09"=>"九月", "10"=>"十月", "11"=>"十一月", "12"=>"十二月" ); function setyear($year){ //设置年份 $this->year=$year; } function getyear(){ //获得年份 return $this->year; } function setmonth($month){ //设置月份 $this->month=$month; } function getmonth(){ //获得月份 return $this->month; } function setday($day){ //设置日期 $this->day=$day; } function getday(){ //获得日期 return $this->day; } function OUT(){ //输出日历 $this->_env(); //设置显示的日期 $week=$this->getweek($this->year,$this->month,$this->day); //获得日期为星期几 $fweek=$this->getweek($this->year,$this->month,1); //获得此月第一天为星期几 echo "

"; for($ttmpa=1;$ttmpa<13;$ttmpa++){ //输出12个月 $ttmpb=sprintf("%02d",$ttmpa); if(strcmp($ttmpb,$this->month)==0){ $select="selected style='background-color:#FAFDE2'"; }else{ $select=""; } echo "".$this->_month[$ttmpb].""; } echo " "; //输出年份,前后10年 for($ctmpa=$this->year-10;$ctmpayear+10;$ctmpa++){ if($ctmpa>2050){ break; } if($ctmpa<1980){ continue; } if(strcmp($ctmpa,$this->year)==0){ $select="selected style='background-color:#FAFDE2'"; }else{ $select=""; } echo "$ctmpa"; } echo "

"; for($Tmpa=0;$Tmpaweek);$Tmpa++){ //输出星期的标头 echo "".$this->week[$Tmpa].""; } for($tmpb=1;$tmpb<=date("t",mktime(0,0,0,$this->month,$this->day,$this->year));$tmpb++){ //输出所有日期 if(strcmp($tmpb,$this->day)==0){ //获得当前日期,并采用特色颜色做为标记 $flag=" bgcolor='#FF3366'"; }else{ $flag=' bgcolor=#FAFDE2'; } if($tmpb==1){ echo "

"; for($tmpc=0;$tmpc"; } } if(strcmp($this->getweek($this->year,$this->month,$tmpb),0)==0){ //如果是周日 echo "

$tmpb"; }else{ echo "$tmpb"; } } echo ""; } //获得方法内指定的日期的星期数 function getweek($year,$month,$day){ $week=date("w",mktime(0,0,0,$month,$day,$year)); //获得星期 return $week; //获得星期 } function _env(){ if(isset($_POST["month"])){ $month=$_POST["month"]; }else{ $month=date("m"); //默认为本月 } if(isset($_POST["year"])){ $year=$_POST["year"]; }else{ $year=date("Y"); //默认为本年 } $this->setyear($year); $this->setmonth($month); $date=sprintf('%1d',date('d')); $this->setday($date); }} $D=new calendar; $D->OUT(); ?>

在index.php里面直接引用该文件

2、最新文章显示:

execute_dql($sql); $i=1; while($info=$res->fetch_assoc()){ ?>

more.gif这里我去查询数据库的时候使用了自己的工具类sqlHelper.class.php

这里给出上面用到的方法实现代码:

sqlHelper.class.php部分代码:

class SqlHelper{ public $mysqli; public $dbname="db_tmlog"; public $username="root"; public $password="root"; public $host="localhost"; public function __construct(){ $this->mysqli = new mysqli($this->host, $this->username, $this->password, $this->dbname); if($this->mysqli->connect_error){ die("连接失败".$this->mysqli->connect_error); } $this->mysqli->query("set names utf8"); } //执行dql语句 public function execute_dql($sql){ $res = $this->mysqli->query($sql) or die($this->mysqli->error); //这里返回的是一个结果集,当调用$row = $res->fetch_assoc()时是一条一条的向下走,应该使用while循环 return $res; } }

dql语句就是简单的查询语句。

在使用数据库查询之前,先把这个文件包进去,然后new一个工具类对象,然后使用对象调用里面的函数。

3、最新图片显示

$sql="select id,tpmc,file from tb_tpsc order by id desc limit 2";$res2 = $sqlHelper->execute_dql($sql);while($info=$res2->fetch_assoc()){$query="select * from tb_tpsc where id=".$info['id']; $result=$sqlHelper->execute_dql($query); if($row = $result->fetch_assoc()){ $data = $row['file']; }?>

<?php%20echo%20%24data;?>

图片名称:

more.gif

同样使用了数据库查询。

4、公告区实现

在公告区使用了我以前没有见过的一个标签

它里面设置了一些属性,就是当鼠标停留在上面的时候它就停止滚动,离开的时候就开始滚动。

$p_sql = "select * from tb_public order by id desc"; $p_rst = $sqlHelper->execute_dql($p_sql);?>while($p_row = $p_rst->fetch_row()){?>这个标签是HTML5新增的,还有center标签。那么在使用的时候就会出现下面画黄色波浪线的情况,我没有去管他。

到这里我们的首页基本就实现了。这是index.php 的完整代码:index.php提取码:iu09

相关文章

相关视频

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值