PHP Using template Paging program (with demo), this is a more classic PHP page code Oh, using the program template, page separation of the way to do this file paging function, it is too cow B.
PHP tutorial using template Paging Program (with demo demo);
This is a more classic PHP page code Oh, using the program template, page separation of the way to do this file paging function, it is too cow B.
*/
page.class.php
Class page{
var $currentpage;
var $leftoffset;
var $rightoffset;
var $totalpage;//Total pages
var $recordcount;//Total Record Count
var $pagesize;//show number of bars per page
var $pageurl;
var $hypelink;
var $template;
var $tpl;
var $tagitems =array ();
var $tagvalues =array ();
var $sqlquery;
constructor function
Function page ($currentpage =1, $pagesize =5, $leftoffset =2, $rightoffset =7, $pageurl = "? page=") {
echo "Start of the paging class";
$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 ();
}
Total Records obtained
$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];//Total Records obtained
}
$this->totalpage=ceil ($this->recordcount/$this->pagesize);//Calculate Total Pages
if ($this->currentpage > $this->totalpage) {$this->currentpage= $this->totalpage;} Determines 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 pass 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 get template file ... File does not exist ";
Exit ();
}
Get Chunk Content
$start =strpos ($this->template, " ");
$end =strpos ($this->template, " ");
$this->tpl=substr ($this->template, $start +strlen (" "), $end-$start-strlen (" ")-2);
If the contents of the IF ($this->tpl== "") {echo "Template are empty, check that the label settings are correct. "; exit ();}
Echo $this->tpl;
}1 2 3
http://www.bkjia.com/PHPjc/444873.html www.bkjia.com true http://www.bkjia.com/PHPjc/444873.html techarticle PHP using template Paging program (with demo), this is a more classic PHP page code Oh, using the program template, page separation of the way to do this file paging function, it is ...