Class PAGE {
- // Starts the class
- /*************************************** *****************
- * $ Total number of records
- * $ PageNum number of entries per page
- * $ Url = ''link
- * $ Page-> StartPage (display classification statistics, character classification/numeric paging, jump );
- * $ Page-> StartPage (true/false, true/false, true/false );
- * Site http://bbs.it-home.org
- **************************************** *****************/
- Private $ total; // The total number of records.
- Private $ pageNum; // Number of Entries displayed per page
- Private $ page; // The current page number.
- Private $ pages; // The total number of pages.
- Private $ url; // page url
- Private $ Aque; // URL parameter
-
- /* Constructor */
- Public function PAGE ($ total, $ pageNum, $ url = '? '){
- $ This-> total = $ total; // The total number of records.
- $ This-> pageNum = $ pageNum; // Number of Entries displayed per page.
- $ This-> url = $ this-> StrSift ($ url); // checks whether the value of $ url is valid.
- $ This-> Aque =$ _ GET; // parameters originally passed on the page.
- $ This-> page = $ this-> StrSift ($ _ GET ['Page']); // GET (global variable) mode parameter of the current page, current page number.
- $ This-> page = is_numeric ($ this-> page )? $ This-> page: 1; // when the current page number is not a number, set it to 1.
- $ This-> pages = ceil ($ total/$ pageNum); // The total number of pages.
- If ($ this-> page <1) $ this-> page = 1; // when the page number is smaller than 1, set it to 1.
- // If ($ this-> page> $ this-> pages) $ this-> page = $ this-> pages; // when the page number is greater than the maximum page number, set it to the maximum page number.
- }
- /******************
- * Paging method
- *******************/
- Function StartPage ($ str, $ view = true, $ jump = true ){
- If ($ view = true) $ PageStr. = $ this-> GetCount (); // page statistics
- If ($ str = 'str') $ PageStr. = $ this-> GetPageStr (); // select the character paging form
- Else $ PageStr. = $ this-> GetPageNum (); // select the number pagination form
- If ($ jump = true) $ PageStr. = $ this-> JumpSelect (); // jump
- Return $ PageStr;
- }
/*************************************** *******
- * Display statistics. Format: 5 Record pages: 2/3
- **************************************** *******/
- Function GetCount (){
- $ CountStr = "total". $ this-> total. "record page:". $ this-> page. "/". $ this-> pages ."";
- Return $ CountStr;
- }
/*************************************** ********
- * Page format 1: First Page Previous Page Last Page
- **************************************** ********/
- Function GetPageStr (){
- $ Url = $ this-> url; // Obtain the URL
- // Process URL parameters: the key of the array is the URL variable, and the value of the array is the value of the URL variable.
- Foreach ($ this-> Aque as $ key => $ val ){
- Switch ($ key ){
- Case "page ":
- $ Next = $ val + 1;
- $ Prev = $ val-1;
- Break;
- Default:
- $ Sque. = "& $ key =". $ this-> StrSift ($ val );
- }
- }
- If ($ Next = 0) $ Next = 2;
- // Previous Page
- Switch ($ this-> page ){
- Case $ this-> page <= 1:
- $ Pagestr. = "first page ";
- $ Pagestr. = "previous page ";
- Break;
- Default:
- $ Pagestr. = "first page ";
- $ Pagestr. = "previous page ";
- }
- // The last page of The Next page
- Switch ($ this-> page ){
- Case $ this-> page >=$ this-> pages:
- $ Pagestr. = "next page ";
- $ Pagestr. = "Last page ";
- Break;
- Default:
- $ Pagestr. = "next page ";
- $ Pagestr. = "pages $ Sque '> last page ";
- }
- // Returns the paging string.
- Return $ pagestr;
- }
/*************************************** ********************
- * Page format: 4307 records page: 1/72 1 2 3 4 5 6 7 8 9 10
- **************************************** ********************/
- Function GetPageNum (){
- $ Url = $ this-> url;
- // Process URL parameters: the key of the array is the URL variable, and the value of the array is the value of the URL variable.
- Foreach ($ this-> Aque as $ key => $ val ){
- Switch ($ key ){
- Case $ key! = "Page ":
- $ Sque. = "& $ key =". $ this-> StrSift ($ val );
- }
- }
- Switch ($ this-> pages ){
- // The total number of pages is greater than 12:
- Case $ this-> pages> 12:
- // Before the number displayed on the page: <
- Switch ($ this-> page ){
- Case $ this-> page> 1:
- $ Pagestr. = "<";
- $ Pagestr. = "page-1). $ Sque." '> <";
- Break;
- Default:
- $ Pagestr. = "<";
- $ Pagestr. = "<";
- }
- // Pagination number: 1 2 3 4 5 6 the current page number has 6 pagination links on the left and 6 pagination links on the right.
- For ($ I = $ this-> page-6; $ I <= $ this-> page + 6; $ I ++ ){
- If ($ I> $ this-> pages) break;
- If ($ I ==$ this-> page) $ pagestr. = $ I ."";
- Elseif ($ I> = 1) $ pagestr. = "$ I ";
- }
- // After the paging number: >>>
- Switch ($ this-> page ){
- Case $ this-> page <$ this-> pages:
- $ Pagestr. = "page + 1). $ Sque." '>>> ";
- $ Pagestr. = "pages. $ Sque." '> ";
- Break;
- Default:
- $ Pagestr. = "> ";
- $ Pagestr. = "> ";
- }
- Break;
- Default:
- // The total number of pages is less than 12:
- For ($ I = 1; $ I <= $ this-> pages; $ I ++ ){
- Switch ($ I ){
- Case $ I ==$ this-> page:
- $ Pagestr. = $ I ."";
- Break;
- Default:
- $ Pagestr. = "$ I ";
- }
- }
- }
- // Returns the paging string.
- Return $ pagestr;
- }
-
- /************************
- * Define the jump page. BEGIN
- *************************/
- Function JumpSelect (){
- $ Url = $ this-> url;
- // Process URL parameters: the key of the array is the URL variable, and the value of the array is the value of the URL variable.
- Foreach ($ this-> Aque as $ key => $ val ){
- If ($ key! = "Page") $ Sque. = "& $ key =". $ this-> StrSift ($ val );
- }
- $ SelectStr = "\ n$ SelectStr. = "onChange = \" window. location = '". $ url ."? Page = '+ this. value +' ". $ Sque." '\ "> \ n ";For ($ I = 1; $ I <= $ this-> pages; $ I ++ ){If ($ I ==$ this-> page) $ selected = "selected ";Else $ selected = "";$ SelectStr. ="$ I\ N ";}$ SelectStr. ="\ N ";
- // Returns the paging string.
- Return $ SelectStr;
- }
/**********************************
- * Filter special characters.
- ***********************************/
- Private function StrSift ($ str ){
- $ Str = str_replace ("\" "," ", $ str );
- $ Str = str_replace ("'", "", $ str );
- $ Str = str_replace ("[url = file: // % 22, % 22% 22, $ str/] \", "", $ str [/url]);
- $ Str = str_replace ("\/", "", $ str );
- $ Str = str_replace (":", "", $ str );
- $ Str = str_replace ("? "," ", $ Str "?? ".
- $ Str = str_replace (">", "", $ str );
- $ Str = str_replace ("<", "", $ str );
- $ Str = str_replace ("%", "", $ str );
- $ Str = str_replace ("*", "", $ str );
- $ Str = str_replace ("&", "", $ str );
- $ Str = str_replace (".", "", $ str );
- Return $ str;
- }
// End the class
- }
- ?>
If you are interested, you can also refer to the following article: A good php paging class code and a practical php paging class Pagination style sheet:
|