Home > php教程 > php手册 > php利用模板分页程序(带demo演示);(1/3)

php利用模板分页程序(带demo演示);(1/3)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:24:20
Original
830 people have browsed it

php利用模板分页程序(带demo演示);这是一款比较经典的php分页代码哦,利用了程序模板,页面分离的方式来做这个文件分页功能,实在是太牛B了。

php教程利用模板分页程序(带demo演示);
这是一款比较经典的php分页代码哦,利用了程序模板,页面分离的方式来做这个文件分页功能,实在是太牛b了。
*/
//page.class.php


class page{

 var $currentpage;
 var $leftoffset;
 var $rightoffset;
   
 var $totalpage;//总页数
 var $recordcount;//总记录数
 var $pagesize;//每页显示条数

 var $pageurl;
 var $hypelink;

 var $template;
 var $tpl;
 var $tagitems=array();
 var $tagvalues=array();

 var $sqlquery;

 //构造函数
 function page($currentpage=1,$pagesize=5,$leftoffset=2,$rightoffset=7,$pageurl="?page="){
  echo "分页类开始";
  $this->currentpage=ceil(abs(@$currentpage+0));
  (empty($this->currentpage))?$this->currentpage=1:$this->currentpage=$this->currentpage;
  $this->pagesize=ceil(abs(@$pagesize+0));
  (empty($this->pagesize))?$this->pagesize=5:$this->pagesize=$this->pagesize;
  $this->leftoffset=ceil(abs(@$leftoffset+0));
  (empty($this->leftoffset))?$this->leftoffset=2:$this->leftoffset=$this->leftoffset;
  $this->rightoffset=ceil(abs(@$rightoffset+0));
  (empty($this->rightoffset))?$this->rightoffset=7:$this->rightoffset=$this->rightoffset;
  $this->pageurl=$pageurl;

  $this->setdefaulttagvalue();
 }
   
 //取得记录总数
 //$sql="select count(id) as n from table";
 function getrecordcount($sql,$conn){
  $query=@mysql教程_query($sql,$conn);
  if(!$query){echo "执行sql语句失败";exit();}
  while($rs=mysql_fetch_row($query)){
   $this->recordcount=$rs[0];//取得记录总数
  }
  $this->totalpage=ceil($this->recordcount / $this->pagesize);//计算总页数
  if($this->currentpage > $this->totalpage){$this->currentpage=$this->totalpage;}//判断当前页是否大于总页数
  mysql_free_result($query);
 }
   
 //select * from tb p->setlimit();
 function setlimit(){
  $limit="limit ".($this->currentpage-1)*$this->pagesize;
  $limit.=",$this->pagesize";
  return $limit;
 }
 
 function executesql($sql,$conn){
  if(!$sql||!$conn){echo "参数传递错误";return false;}
     $this->sqlquery=mysql_query($sql,$conn);
     if(!$this->sqlquery){echo "执行sql语句失败";return false;}
 }
 function recordset(){
  return mysql_fetch_array($this->sqlquery);
 }
   
 //取得模板内容
 function gettemplate($filedir){
  if(file_exists($filedir)){
   $f=fopen($filedir,"r");
   $this->template=fread($f,filesize($filedir));
  }else{
   echo "获取模板文件失败...文件不存在";
   exit();
  }
  //取得区块内容
  $start=strpos($this->template,"");
  $end=strpos($this->template,"");
  $this->tpl=substr($this->template,$start+strlen(""),$end-$start-strlen("")-2);
  if($this->tpl==""){echo "模板内容为空,请检查标签设置是否正确。";exit();}
  //echo $this->tpl;
 }1 2 3

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template