Tutorial similar to dz paging code _ PHP

Source: Internet
Author: User
Similar to dz paging code. Example of how to implement a class in a page scroll bar :? PhpClass_Scroll: _ Print ($ _ SERVER [PHP_SELF], 1234, $ _ GET [Page], 10, $ _ SERVER [QUERY_STRING], Page, 9, true ); class implemented by a page scroll bar

Usage example:


Class_Scroll: _ Print ($ _ SERVER ['php _ self-service '], 1234, $ _ GET ['Page'], 10, $ _ SERVER ['query _ string'], "Page", 9, true );
?>

/**
* Implement the scroll bar class
*
* Generate a page scroll bar for Display/control based on the page content and data volume.
*
* Class_Scroll::_Print($_SERVER['PHP_SELF'],1234,$_GET['Page'],10,$_SERVER['QUERY_STRING'],"Page",9,true);
*

*
* @ Author Zhou Beichen 2006-7-16
* @ Version 2.1
*
* @ Todo generate a page content scroll bar
*/
Class Class_Scroll {
/**
* Scroll bar of the output page
*
* @ Param string $ AScriptName the page to be rolled
* @ Param integer $ ATotalCount the total number of scrolling information
* @ Param integer $ ANowPageID current page number
* @ Param integer $ AInnerCount the number of messages on each page
* @ Param string $ other variables to be included with AVar and their values
* @ Param string $ APageKey is used to specify the variable name of the page number.
* @ Param integer $ APageBundle indicates the maximum number of pages displayed in the scroll bar.
* @ Param boolean $ IncJump whether the page jump drop-down list is displayed (default: true)
* @ Return string HTML code in the scroll bar of the page
*/
Function _ Print ($ AScriptName, $ ATotalCount, $ ANowPageID, $ AInnerCount, $ AVar, $ APageKey = "Page", $ APageBundle = 9, $ IncJump = true ){
// No project
If ($ ATotalCount = 0 or $ ATotalCount = "") return "No related content."; // "No Item Here .";
// Calculate the total number of pages
$ PageCount = ceil ($ ATotalCount/$ AInnerCount );
// Check and control the current page number
If ($ ANowPageID <1) $ ANowPageID = 1;
If ($ ANowPageID> $ PageCount) $ ANowPageID = $ PageCount;
// Determine the digital link value to be displayed.
$ StartNum = ($ ANowPageID-floor ($ APageBundle/2)> 0? ($ ANowPageID-floor ($ APageBundle/2): 1;
$ EndNum = ($ PageCount-$ StartNum) <$ APageBundle? $ PageCount: ($ StartNum + $ APageBundle-1 );
If ($ EndNum-$ StartNum) <$ APageBundle) & ($ PageCount> $ APageBundle) $ StartNum = $ EndNum-$ APageBundle + 1;
// Obtain the variable
If (strlen ($ AVar)> 0) $ Vars = explode ("&", $ AVar );
If (count ($ Vars)> 0 ){
For ($ I = 0; $ I $ V = explode ("=", $ Vars [$ I]);
If ($ v [0]! = $ APageKey) $ VarString. = sprintf ("% s = % s &", $ v [0], $ v [1]);
}
}
// Home page
$ OutStringr = sprintf ('% s % s', $ AScriptName, $ VarString, $ APageKey, "1", "homepage", "r ");
// Previous page link
$ OutStringr. = ($ ANowPageID = 1 )? "": Sprintf ('% s % s', $ AScriptName, $ VarString, $ APageKey, $ ANowPageID-1, "previous", "r ");
// Link to the intermediate page
For ($ I = $ StartNum; $ I <= $ EndNum; $ I ++)
$ OutStringr. = ($ I = $ ANowPageID )? Sprintf ("% s", $ I, "r"): sprintf ('% s % s', $ AScriptName, $ VarString, $ APageKey, $ I, $ I, "r ");
// Next page
$ OutStringr. = ($ ANowPageID = $ PageCount )? "": Sprintf ('% s % s', $ AScriptName, $ VarString, $ APageKey, $ ANowPageID + 1, "next page", "r ");
// Link to the last page
$ OutStringr. = sprintf ('% s Page % s % s', $ AScriptName, $ VarString, $ APageKey, $ PageCount, "last page", $ PageCount, $ ATotalCount, "r ");
// Jump link
If ($ IncJump ){
$ OutStringr. = sprintf ("Jump to (J ):% S ", $ AScriptName, $ VarString, $ APageKey," r ");For ($ I = 1; $ I <= $ PageCount; $ I ++ ){$ SelectedStr = ($ I = $ ANowPageID )? "Selected =" selected "":"";$ OutStringr. = sprintf ("Page % d% S ", $ I, $ SelectedStr, $ I," r ");}$ OutStringr. ="";
}
// Output
Return $ OutStringr;
}
}
?>


Example :? Php Class_Scroll: _ Print ($ _ SERVER ['php _ SELF '], 1234, $ _ GET ['Page'], 10, $ _ SERVER ['query _ string'], Page, 9, true );...

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.