Home  >  Article  >  Backend Development  >  PHP uses template paging program (with demo demonstration); (1/3)_PHP tutorial

PHP uses template paging program (with demo demonstration); (1/3)_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:08:26934browse

PHP uses template paging program (with demo demonstration); this is a relatively classic PHP paging code. It uses program templates and page separation to achieve this file paging function. It is really awesome.

php tutorial uses template paging program (with demo demonstration);
This is a relatively classic php paging code. It uses program templates and page separation to achieve this file paging function. It is really awesome. b.
*/
//page.class.php


class page{

var $currentpage;
var $leftoffset;
var $rightoffset ;
 
var $totalpage;//Total number of pages
var $recordcount;//Total number of records
var $pagesize;//Number of items displayed per page

var $ pageurl;
var $hypelink;

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

var $sqlquery;

//Constructor
function page($currentpage=1,$pagesize=5,$leftoffset=2,$rightoffset=7,$pageurl="?page ="){
echo "Paging class starts";
$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();
}

//Get the total number of records
//$sql="select count(id) as n from table";
function getrecordcount($sql,$conn){
$query=@mysql tutorial_query($sql,$conn);
if(!$query){echo "Failed to execute sql statement";exit();}
while($rs=mysql_fetch_row($query)){
$this->recordcount=$rs[ 0];//Get the total number of records
}
$this->totalpage=ceil($this->recordcount / $this->pagesize);//Calculate the total number of pages
if( $this->currentpage > $this->totalpage){$this->currentpage=$this->totalpage;}//Determine whether the current page is greater than the total number of pages
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 "Parameter passing error";return false;}
$this->sqlquery=mysql_query($sql,$conn);
if(!$this->sqlquery){echo "Failed to execute sql statement";return false;}
}
function recordset(){
return mysql_fetch_array($this->sqlquery) ;
}

//Get template content
function gettemplate($filedir){
if(file_exists($filedir)){
$f=fopen($filedir," r");
$this->template=fread($f,filesize($filedir));
}else{
echo "Failed to obtain the template file...The file does not exist";
exit();
}
//Get block content
$start=strpos($this->template,"");
$end=strpos($this->template,"");
$this->tpl=substr($this->template,$start+strlen (""),$end-$start-strlen("")-2);
if($this-> tpl==""){echo "The template content is empty, please check whether the label settings are correct. ";exit();}
//echo $this->tpl;
}1 2 3

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444873.htmlTechArticlephp uses template paging program (with demo demonstration); this is a relatively classic php paging code, use Using program templates and page separation to implement this file paging function is really...
Statement:
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