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;$ttmpamonth)==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($ctmpayear)==0){ $select=selected style='background-color:#fafde2'; }else{ $select=; } echo $ctmpa; } echo
; for($tmpa=0;$tmpaweek);$tmpa++){ //输出星期的标头 echo .$this->week[$tmpa]. ; } for($tmpb=1;$tmpbmonth,$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()){ ?>
这里我去查询数据库的时候使用了自己的工具类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、最新图片显示
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']; } ?> width=120 style=max-width:90% border=0>
图片名称:
同样使用了数据库查询。4、公告区实现
在公告区使用了我以前没有见过的一个标签
它里面设置了一些属性,就是当鼠标停留在上面的时候它就停止滚动,离开的时候就开始滚动。
execute_dql($p_sql);?>fetch_row()){?>
这个标签是html5新增的,还有center标签。那么在使用的时候就会出现下面画黄色波浪线的情况,我没有去管他。在这个超链接标签里,它设置了onclick这个属性,onclick这个属性后面跟的一定是js文件里面的函数,这个是打开一个自定义宽高的窗口。href=#表示这个超链接不连接到其他页面,这里超链接的响应使用onclick来设定了。
到这里我们的首页基本就实现了。这是index.php 的完整代码:index.php提取码:iu09