Two simple and easy paging classes

xiaoxiao2021-03-06  61

Class Page {

/ *

Class Function: Page

Create time: 2005-03-12

Author: multi-rookie

Email: Kingerq at sohu.com

Source: http://blog.9cbs.net/kingerq

Example:

/ / Omit some connection information and mysql class libraries

$ SQL = "SELECT Count (*) from t_publiccode";

$ dB-> query ($ SQL);

$ dB-> next_record ();

$ RecordCount = $ db-> f (0); // Total number of records

$ P = New Page ($ RecordCount, 20, 15); // (total record number, number per page, number of page number per page)

$ P-> ar = array ("« Home ","

$ trunpage = p-> show_page (); // Get paging information

$ SQL = "Select * from t_publiccode". $ P-> limited ();

// echo $ trunpage. "
". $ SQL;

$ dB-> query ($ SQL);

// ...

Similar effects:

Total [52600] record / total [2630] Page Last >>

* /

Var $ pageCOUNT; / / total page number

Var $ limit = ""; // use the LIMIT parameter used when

Var $ Pagearg = "Page"; // Paging Parameter Name

VAR $ PAGESIZE = 20; // Mark per page

Var $ recordcount; // total record number

Var $ PAGENUM; // Current page number

Var $ argstr = ""; // Get parameter string

Var $ perpage = 5; // Demodes of page each time

Var $ ar = array ("[«] "," [<] "," [>], "[»] ");

/ *

* Function: Constructor

* Parameters $ recordcount for the total number of records

* Parameters $ PageSize Display the number of records per page, default is 20

* Parameters $ perpage for each display page number, default is 5

* /

Function Page ($ Recordcount, $ PageSize = 20, $ perpage = 5) {

$ this-> Pagesize = $ pageize;

$ this-> Recordcount = $ recordcount;

$ this-> perpage = $ perpage;

$ this-> PageCount = CEIL ($ RecordCount / $ pageSize); // Total number

$ this-> Pagenum = $ this-> currentpage (); // Current page number

$ this-> argstr = $ this-> newarg (); // Get parameter string

$ this-> limit = "limited". ($ this-> Pagenum-1) * $ pageSize. ",". $ pageize; // Sub-paged Limit parameter}

/ *

* Function: Get the current page number function

* /

Function currentpage () {

IF (isset ($ _ get [$ this-> pagearg])) {

IF ($ _ Get [$ THIS-> Pagearg] <= 0) {

$ Page = 1;

Else IF ($ _ Get [$ this-> Pagearg]> $ this-> pagecount) {

$ Page = $ this-> pagecount;

} else {

$ Page = $ _Get [$ this-> Pagearg];

}

} else {

$ Page = 1;

}

Return $ PAGE;

}

/ *

* Function: Reorganization GET parameters

* /

Function newarg () {

$ Str = "";

$ urlar = $ _get;

UNSET ($ Urlar [$ this-> Pagearg]);

IF ($ URLAR) {

Foreach ($ Urlar AS $ Key => $ VAL) {

IF ($ STR == "") {

$ STR = "? $ key = $ val";

} else {

$ Str. = "& $ Key = $ VAL";

}

}

$ Str. = "& $ this-> Pagearg =";

} else {

$ STR = "? $ this-> Pagearg =";

}

Return $ STR;

}

/ *

* Function: Return to the Limit section of the mysql statement

* /

Function Limit () {

Return $ this-> limit;

}

/ *

* Function: Subset Character Output Function

* /

Function show_page () {

$ trunpage = "Total [". $ this-> RecordCount. "] Strip / total [". $ this-> pagecount. "] page

$ Page = $ this-> Pagenum;

/ / Turn forward

IF ($ PAGE == 1) {

$ trunpage. = $ THIS-> Ar [0]. "" "$ this-> ar [1]."

} else {

$ trunpage. = '. $ this-> ar [0].' > Argstr.'1 "> '. $ this-> ar [0].' '. $ THIS -> ar [1]. '';

}

/ / Intermediate digital page

$ Numpage = 1;

While ($ page - $ this-> perpage * $ numpage> 0) $ Numpage ;

$ startPage = ($ Numpage - 1) * $ this-> perpage; $ endpage = $ this-> pagecount: $ this-> PageCount: $ Numpage * $ this-> perpage;

For ($ I = $ startPAGE 1; $ i <= $ endpage; $ i ) {

$ trunpage. = $ I! = $ page? " $ i :" ". $ I. "";

}

//

IF ($ Page == $ this-> PageCount || $ this-> pagecount == 0) {

$ trunpage. = $ this-> ar [2]. "" "" $ this-> ar [3]. "

} else {

$ trunpage. = '". $ this-> ar [2]. ' '. $ this-> ar [3]. '';

}

// jump

$ SELECT = " / n";

For ($ i = 1; $ i <= $ this-> pagecount (); $ i ) {if ($ this-> currentpage == $ i) $ SELECTED = "SELECTED";

ELSE $ SELECTED = ""

$ PageStr. = "

}

$ PageStr. = "";

Return $ PageStr;

}

// Current page parameters

Function paramstr () {

Unset ($ _GET [$ this-> paramname]); // Remove the page parameters

IF (count ($ _GET)) {

Foreach ($ _GET AS $ Param => $ value) {

$ this-> paramstr. = $ tris-> paramstr? "&": "?";

$ this-> paramstr. = $ param. "=". $ value;

}

$ this-> paramstr. = "&". $ this-> paramname. "=";

} else {

$ this-> paramstr = "$ this-> paramname =";

}

}

// get the current page number

Function currentpage () {

IF (isset ($ _GET [$ this-> paramname]) && intVal ($ _GET [$ this-> paramname])> 0) {

$ this-> currentpage = intVal ($ _Get [$ this-> paramname]);

}

Return $ this-> CurrentPage;

}

//total pages

Function pageCount () {

Return CEIL ($ this-> Recordcount / $ this-> pagesize); // Total number

}

// mysql Limit part string

Function Limitstr () {

Return "Limit". ($ this-> currentpage - 1) * $ this-> pagesize). ",". $ this-> pagesize;

}

/ / Set the number of page numbers per page, the number of page numbers is at least 1

Function setPage ($ NUM = 5) {

IF (INTVAL)> 1)

$ this-> perpage = intVal ($ NUM);

}

}

?>

转载请注明原文地址:https://www.9cbs.com/read-111934.html

New Post(0)