Php uses the template paging program (with demo); (1/3) _ PHP Tutorial

Source: Internet
Author: User
Tags mysql tutorial
Php uses the template paging program (with demo); (13 ). Php uses the template paging program (with demo); this is a classic php paging code. it uses the program template and page separation to implement this file paging function, php uses the pagination program of the template (with demo). This is a classic php paging code. the pagination function of this file is implemented by using the program template and page separation, it's really cool.

The php Tutorial uses the template paging program (with demo );
This is a classic php paging code. Using the program template and page separation for this file paging function is really awesome.
*/
// Page. class. php


Class page {

Var $ currentpage;
Var $ leftoffset;
Var $ rightoffset;

Var $ totalpage; // The total number of pages.
Var $ recordcount; // The total number of records.
Var $ pagesize; // number of entries 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 "start of 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 ();
}

// Retrieve 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 "SQL statement execution failed"; exit ();}
While ($ rs = mysql_fetch_row ($ query )){
$ This-> recordcount = $ rs [0]; // retrieves the total number of records
}
$ This-> totalpage = ceil ($ this-> recordcount/$ this-> pagesize); // calculates the total number of 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 passing error"; return false ;}
$ This-> sqlquery = mysql_query ($ SQL, $ conn );
If (! $ This-> sqlquery) {echo "SQL statement execution failed"; return false ;}
}
Function recordset (){
Return mysql_fetch_array ($ this-> sqlquery );
}

// Obtain the template content
Function gettemplate ($ filedir ){
If (file_exists ($ filedir )){
$ F = fopen ($ filedir, "r ");
$ This-> template = fread ($ f, filesize ($ filedir ));
} Else {
Echo "an error occurred while obtaining the template file... the file does not exist ";
Exit ();
}
// Obtain the 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. check whether the tag settings are correct. "; Exit ();}
// Echo $ this-> tpl;
} 1 2 3

Compile (with demo); this is a classic php paging code. it uses the program template and page separation to implement this file paging function. it is really...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.