PHP
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. " $ dB-> query ($ SQL); // ... Similar effects: Total [52600] record / total [2630] Page * / 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. " strong>"; } // IF ($ Page == $ this-> PageCount || $ this-> pagecount == 0) { $ trunpage. = $ this-> ar [2]. "" "" $ this-> ar [3]. " } else { $ trunpage. = '". $ this-> ar [2]. ' '. $ this-> ar [3]. ''; } // jump $ SELECT = " For ($ I = 1; $ i <= $ this-> pagecount; $ i ) { $ SELECT. = " } $ SELECT. = " select>"; Return $ trunpage. $ SELECT } } ?> PHP / ********************* * General Patement class * Author: Multi-rookie * Email: Kingerq at Sohu Dot COM * Time: 2006-04-17 * Source: http://blog.9cbs.net/kingerq * Instance: $ P = New Page (60, 10); $ P-> Trunstr = Array ("first", "prev", "next", "end"); // Set the paging display character Echo $ P-> PRINTPAGE (); // Output Paging string, you can also use trunup (), trunnum (), trunDown (), and jumpto () to output display // echo $ p-> limitedst (); // Display mysql part string // echo $ P-> PageCount (); // Total number ********************* * / Class Page { VAR $ perpage = 5; / / The number of page numbers VAR $ paramstr = "", // paised parameter string variable, connection address Var $ currentpage = 1; // Current page number Var $ paramname = "pagenum"; // turn the page parameter name Var $ limitstr = ""; // mysql in the LIMIT parameter string VAR $ PAGESIZE = 20; // Per record number Var $ TRUNSTR = Array ("Home", "Page", "Next", "Last"); // Turn the Character / * * Constructor * $ RecordCount for recording total number * $ pageize records for each page * / Function Page ($ Recordcount = 0, $ PAGESIZE = 0) { IF (! is_numeric) ||! is_numeric ($ pageize)) Return; // Total number of records IF (INTVAL ($ RecordCount) == 0) $ RecordCount = $ this-> Recordcount; Else $ this-> Recordcount = $ recordcount; / / Maximum number of records per page IF (INTVAL ($ pagesize) == 0) $ pageize = $ this-> pagesize; Else $ this-> Pagesize = $ pageize; $ this-> currentpage (); // Current page code processing $ this-> paramstr (); // Current page address parameter / / For the current page setting IF ($ this-> CurrentPage> $ this-> pagecount ()) $ this-> CurrentPage = $ this-> PageCount () <1? 1: $ this-> pagecount (); } Function printPage () { $ PageStr = $ this-> Trunup (); // $ PageStr. = $ this-> Trunnum (); // Digital page $ PageStr. = $ this-> trundown (); // $ PageStr. = $ this-> jumpto (); // Jump Return $ PageStr; } / / Turn up Function trunup () { $ PageStr = ""; IF ($ this-> currentpage == 1) { $ PageStr. = $ THIS-> TrunStr [0]. "" $ this-> trunstr [1]. " } else { $ PageStr. = "<'" 1 / "Title = /" ". $ this-> TrunStr [0]." / ">". $ this-> trunstr [ 0] ""; $ PageStr. = "<--> PARAMSTR. ($ this-> currentpage - 1)." / "Title = /" ". $ this-> trunstr [1]." / " > ". $ this-> trunstr [1]." "; Return $ PageStr; } / / Page size connection per page Function trunnum () { $ PageStr = ""; $ Num = 1; While ($ this-> CurrentPage - $ this-> perpage * $ num> 0) $ Num ; $ sart = ($ Num - 1) * $ this-> perpage; $ END = $ this-> PageCount () <$ this-> perpage * $ Num? $ this-> pagecount (): $ this-> perpage * $ num; For ($ I = $ start 1; $ I <= $ END; $ I ) { $ PageStr. = $ I! = $ this-> currentpage? " $ i : " $ i < / STRONG> "; } Return $ PageStr; } / / Turn down Function trunDown () { $ PageStr = ""; IF ($ this-> pagecount () == $ this-> currentpage || $ this-> pagecount () == 0) { $ PageStr. = $ this-> trunstr [2]. "" $ this-> trunstr [3]. " } else { $ PageStr. = "<--> PARAMSTR. ($ THIS-> CurrentPage 1)." / "Title = /" ". $ this-> trunstr [2]." / " > ". $ this-> trunstr [2]." "; $ PageStr. = "<". "/" title = / "". $ this-> trunstr [3 ]-> trunstr [3 ]-> trunstr [3]. . $ this-> trunstr [3]. ""; } Return $ PageStr; } // jump Function jumpto () { $ PageStr = " For ($ i = 1; $ i <= $ this-> pagecount (); $ i ) {if ($ this-> currentpage == $ i) $ SELECTED = "SELECTED"; ELSE $ SELECTED = "" $ PageStr. = " } $ PageStr. = " select>"; 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); } } ?>
". $ SQL;