"二月",">
当前位置:Gxlcms > PHP教程 > PHP经典项目案例-(1)博客管理系统3

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

时间:2021-07-01 10:21:17 帮助过:28人阅读

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($Tmpa=0;$Tmpaweek);$Tmpa++){ //输出星期的标头 echo ""; } 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<$fweek;$tmpc++){ echo ""; } } if(strcmp($this->getweek($this->year,$this->month,$tmpb),0)==0){ //如果是周日 echo ""; }else{ echo ""; } } echo "
".$this->week[$Tmpa]."
$tmpb$tmpb
"; } //获得方法内指定的日期的星期数 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()){        ?>        	
" target="_blank">
   
这里我去查询数据库的时候使用了自己的工具类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']; } ?>
  " target="_blank">  
图片名称:
   

同样使用了数据库查询。

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()){?>','','height=200,width=1000,scollbars=no')">
这个标签是HTML5新增的,还有center标签。那么在使用的时候就会出现下面画黄色波浪线的情况,我没有去管他。

在这个超链接标签里,它设置了onclick这个属性,onclick这个属性后面跟的一定是js文件里面的函数,这个是打开一个自定义宽高的窗口。href="#"表示这个超链接不连接到其他页面,这里超链接的响应使用onclick来设定了。


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


人气教程排行