Which of the following statements can help you see how this paging class is called?

Source: Internet
Author: User
Which one can help me to see how to call this paging class? I am talking about finding a nice paging class on the Internet under the query statement, even though the author has already explained how to call it, but for me, I still don't quite understand, mainly how to call it in SQL statements. below is the paging code:
 '20140901', total number of data items to be displayed; * (required) 'pagesize' => '2', number of codes to be displayed per page; * (required) 'currentpage' => $ _ GET ['P'], current page number, which can be obtained by default through $ _ GET ['P']. the name p can be customized * (required) 'baseurl' => '/welcome? Id = 3', the link address of your current page, for example http://www.xxx.com/test.php (Or/test. php). if it is followed by a parameter, it can be http://www.xxx.com/test?id=8 * (Optional, default value: 3) 'offset' => '3'. the offset between the left and right of the current page. for example, if the current page number is 5, several numeric links are displayed on the left and right sides of 5, the default value is 3, and the effect is 2, 3, 4, 5, 6, 7, 8 * (optional, default value: p) 'pagestring' => 'P ', GET the name of the current page number through $ _ GET ['P']. the default value is p * (optional, the default value is here) 'classname' => 'where ', the style of the current page link button. the default style is here, so you can write the css style like this. here {background: # FF4500;}) ** 2. available methods. * A. After the initialization class, you need to call the pagination ([$ style = '1'] [, $ output = TRUE]) method to generate A paging link * about the parameter description: * @ param $ style (default value: 1, not filled in): Get all components of the link, that is, home page + previous page + digital link + Next Page + Last Page * @ param $ style = 2: only get the number link * @ param $ style = 3: only get the previous page + Next Page * @ param $ style = 4: only get the previous page + number link + next page, (excluding the first and last pages) ** @ param $ output (TRUE by default). If the return pagination link * @ param $ output is FALSE, directly output the paging links ** B and getCurrentPage () to obtain the current page number. if the current page number is determined based on the authenticity of the page, the user cannot enter an error. for example: http://www.xxx.com/test?p=-100 In this case, the current page number is 1 ** C, pageAmount (), and the total page number is obtained ** @ author @ * @ link http://blog.sina.com.cn/yanyinghq **/Class Page {private $ pageSize; // The number of list entries displayed on each Page of your website. private $ totalRows; // The total number of records returned by the database query is private $ url; // reference URL private $ pageAmount; // The total number of pages private $ currentPage; // The current page number private $ offset = 4; // The page number offset private $ pageString = 'p '; // the name of the page number in the URL is private $ classHere = 'class = "here" '; // The class style class name of the current page link. the default value is here // initialize the current page number, total number of records, number of records per page public function _ construct ($ param) {$ this-> pageSize = $ param ['pagesize' ]; $ This-> totalRows = $ param ['totalrows ']; $ this-> url = $ param ['baseurl']; $ this-> offset =! Empty ($ param ['offset'])? $ Param ['offset']: $ this-> offset; $ this-> pageString =! Empty ($ param ['pagestring'])? $ Param ['pagestring']: $ this-> pageString; $ this-> classHere =! Empty ($ param ['classname'])? $ Param ['classname']: $ this-> classHere; $ this-> currentPage = (int) $ param ['currentpage'];} /*** create a paging link ** @ param $ style is 1 by default: Get all components of the link * @ param $ style = 2: only get the number link * @ param $ style = 3: only get the previous page, next page * @ param $ style = 4: only get the previous page, next page, and number link, if ** @ param $ output is set to TRUE and the paging link * @ param $ output is returned to be set to FALSE, directly output the paging link **/public function pagination ($ style = '1', $ output = TRUE) {$ this-> baseUrl (); $ this-> page Amount (); $ this-> currentPage (); // Obtain all components if ($ style = '1') {$ page = $ this-> indexPage (). $ this-> prevPage (). $ this-> pageNumber (). $ this-> nextPage (). $ this-> endPage ();} else if ($ style = '2') {// Get a pure digital link $ page = $ this-> pageNumber ();} else if ($ style = '3') {// only get the next page of the previous page $ page = $ this-> prevPage (). $ this-> nextPage ();} else if ($ style = '4') {// previous page, next page, numeric link $ page = $ this-> prevPage (). $ this-> pageNumber (). $ This-> nextPage () ;}if ($ output) {return $ page ;}else {echo $ page ;}} /*** get the current page ** @ return the current page number, which is determined by the authenticity of the page */public function getCurrentPage () {$ this-> pageAmount (); $ this-> currentPage (); return $ this-> currentPage ;} /*** calculate all pages ** this method can be called outside the class to return the total number of pages ** @ return the total number of pages */public function pageAmount () {$ this-> pageAmount = ceil ($ this-> totalRows/$ this-> pageSize); if ($ this-> pageAmount <= 0) {$ This-> pageAmount = '1';} return $ this-> pageAmount ;} /*** determine whether the reference link carries the parameter ** the reference link submits the current page number link for the user **. if the reference link carries the parameter, add & p = ** after the link. If no parameter is included, add? P = */private function baseUrl () {if (preg_match ('/\? /', $ This-> url) {$ this-> url = $ this-> url. '&'. $ this-> pageString. '=';} else {$ this-> url = $ this-> url. '? '. $ This-> pageString. '=';}/*** verify the authenticity of the current page ** if the current page number is less than 1 or does not exist, the default current page number is 1 ** if the current page number is greater than the total number of pages, by default, the current page number is the total number of pages **/private function currentPage () {if ($ this-> currentPage <1 |! $ This-> currentPage) {$ this-> currentPage = 1;} else if ($ this-> currentPage> $ this-> pageAmount )) {$ this-> currentPage = $ this-> pageAmount;}/*** homepage link */private function indexPage () {if ($ this-> currentPage = 1) return; return 'URL. '1 "> homepage ';}/*** link to the last page */private function endPage () {if ($ this-> currentPage ==$ this-> pageAmount) return; return 'URL. $ this-> pageAmount. '"> last page';}/*** previous page */priva Te function prevPage () {if ($ this-> currentPage = 1) return; return 'URL. ($ this-> currentPage-1 ). '"> Previous Page';}/*** next page */private function nextPage () {if ($ this-> currentPage ==$ this-> pageAmount) return; return 'URL. ($ this-> currentPage + 1 ). '"> Next Page';}/*** link to the intermediate page number **/private function pageNumber () {$ left =" "; $ right = ""; // if the total number of records is greater than the number of all links, if ($ this-> pageAmount> ($ this-> offset * 2 + 1) {// The distance between the current page number and the home page $ leftNum = $ this-> currentPage-1; // The distance between the current page number and the last page $ rightNum = $ this-> pageAmount-$ this-> currentPage; // when the current page number is offset from the offset when the current page number is less than the last page number, fill in the missing small square if ($ leftNum <$ this-> offset) {// link on the left for ($ I = $ leftNum; $ I> = 1; $ I --) {$ left. = 'URL. ($ this-> currentPage-$ I ). '"> '. ($ this-> currentPage-$ I ). '';} // link to the right ($ j = 1; $ j <= ($ this-> offset * 2-$ leftNum); $ j ++) {$ right. = 'URL. ($ This-> currentPage + $ j ). '"> '. ($ this-> currentPage + $ j ). '';} else if ($ rightNum <$ this-> offset) {// link on the left ($ I = ($ this-> offset * 2-$ rightNum); $ I >=1; $ I --) {$ left. = 'URL. ($ this-> currentPage-$ I ). '"> '. ($ this-> currentPage-$ I ). '';} // The link to the right for ($ j = 1; $ j <= $ rightNum; $ j ++) {$ right. = 'URL. ($ this-> currentPage + $ j ). '"> '. ($ this-> currentPage + $ j ). '';} else {// link on the left of the current link For ($ I = $ this-> offset; $ I >=1; $ I --) {$ left. = 'URL. ($ this-> currentPage-$ I ). '"> '. ($ this-> currentPage-$ I ). '';} // link to the right of the current link for ($ j = 1; $ j <= $ this-> offset; $ j ++) {$ right. = 'URL. ($ this-> currentPage + $ j ). '"> '. ($ this-> currentPage + $ j ). '';} return $ left. 'URL. $ this-> currentPage. '"class =" here "> '. $ this-> currentPage. ''. $ right;} else {$ allLink = ''; // when the total number of pages is less than the number of links to be displayed, all are displayed ($ J = 1; $ j <= $ this-> pageAmount; $ j ++) {$ allLink. = 'URL. $ j. '"'. ($ j = $ this-> currentPage? $ This-> classHere: ''). '>'. $ j.'';} return $ allLink ;}}}


Reply to discussion (solution)

Here is the php call page, the following code:

 Untitled Document  
 '20140901', 'pagesize' => '2', 'currentpage' = >@$ _ GET ['P'], 'baseurl' => '/page_index.php? Id = 3'); $ page1 = new Page ($ param); $ page2 = new Page ($ param); $ page3 = new Page ($ param ); $ page4 = new Page ($ param); $ page5 = new Page ($ param); this should be an SQL query statement in the middle, however, I don't know how to call the paging function, but I do not know how to write echo 'total number of records: 100 '; echo'
 '; Echo' 2 records per page
 '; Echo 'current page number:'. $ page1-> getCurrentPage ().'
 '; Echo' Total '. $ page1-> pageAmount ().' page
 '; Echo'
  • '. $ Page1-> pagination ().'
  • '; Echo'
  • '. $ Page2-> pagination ('1 ').'
  • '; // The default value is 1, so the effect is the same as that of the unspecified echo'
  • '. $ Page3-> pagination ('2 ').'
  • '; Echo'
  • '. $ Page4-> pagination ('3 ').'
  • '; Echo'
  • '. $ Page5-> pagination ('4 ').'
  • ';?>

    This class is only responsible for generating paging entries
    The only option that may be related to database queries is the parameter array $ param ['totalrows '].
    Because the total number of rows to be paged is queried, this query should be completed before the $ param value is assigned.

    This class is only responsible for generating paging entries
    The only option that may be related to database queries is the parameter array $ param ['totalrows '].
    Because the total number of rows to be paged is queried, this query should be completed before the $ param value is assigned.


    How should the moderator write this?

    The landlord is too lazy. I have a style for you.

     "Records", "prev" => "previous page", "next" => "next page", "first" => "first page ", "last" => "last page"); private $ listNum = 8;/* $ total 11. * $ listRows 12. */public function _ construct ($ total, $ listRows = 10, $ pa = "") {$ this-> total = $ total; $ this-> listRows = $ listRows; $ this-> uri = $ this-> getUri ($ pa); $ this-> page =! Empty ($ _ GET ["page"])? $ _ GET ["page"]: 1; $ this-> pageNum = ceil ($ this-> total/$ this-> listRows ); $ this-> limit = $ this-> setLimit ();} private function setLimit () {return "Limit ". ($ this-> page-1) * $ this-> listRows. ", {$ this-> listRows}";} private function getUri ($ pa) {$ url = $ _ SERVER ["REQUEST_URI"]. (strpos ($ _ SERVER ["REQUEST_URI"], '? ')? '':"? "). $ Pa; $ parse = parse_url ($ url); if (isset ($ parse ["query"]) {parse_str ($ parse ['query'], $ params ); unset ($ params ["page"]); $ url = $ parse ['path']. '? '. Http_build_query ($ params);} return $ url;} public function _ get ($ args) {if ($ args = "limit") return $ this-> limit; else return null;} private function start () {if ($ this-> total = 0) return 0; else return ($ this-> page-1) * $ this-> listRows + 1;} private function end () {return min ($ this-> page * $ this-> listRows, $ this-> total );} private function first () {if ($ this-> page = 1) $ html. = ''; else $ html. ="
  • Uri} & page = 1' >{$ this-> config ["first"]}
  • "; Return $ html;} private function prev () {if ($ this-> page = 1) $ html. =''; else $ html. ="
  • Uri} & page = ". ($ this-> page-1)." '>{$ this-> config ["prev"]}
  • "; Return $ html;} private function pageList () {$ linkPage =" "; $ inum = floor ($ this-> listNum/2 ); for ($ I = $ inum; $ I >=1; $ I --) {$ page = $ this-> page-$ I; if ($ page <1) continue; $ linkPage. ="
  • Uri} & page = {$ page} '> {$ page}
  • ";}$ LinkPage. ="
  • {$ This-> page}
  • "; For ($ I = 1; $ I <= $ inum; $ I ++) {$ page = $ this-> page + $ I; if ($ page <= $ this-> pageNum) $ linkPage. ="
  • Uri} & page = {$ page} '> {$ page}
  • "; Else break;} return $ linkPage;} private function next () {if ($ this-> page = $ this-> pageNum) $ html. = ''; else $ html. ="
  • Uri} & page = ". ($ this-> page + 1)." '>{$ this-> config ["next"]}
  • "; Return $ html;} private function last () {if ($ this-> page ==$ this-> pageNum) $ html. = ''; else $ html. ="
  • Uri} & page = ". ($ this-> pageNum)." '>{$ this-> config ["last"]}
  • "; Return $ html;}/* private function goPage () {return' ';} */Private function goPage () {return'';} Function fpage ($ display = array (0, 2, 3, 4, 5, 6, 7, 8) {$ html [0] = "total{$ This-> total}{$ This-> config ["header"]} "; $ html [1] =" displayed on each page". ($ This-> end ()-$ this-> start () + 1 ).", This page{$ This-> start ()}-{$ this-> end ()}"; $ Html [2] ="{$ This-> page}/{$ this-> pageNum}Page "; $ html [3] = $ this-> first (); $ html [4] = $ this-> prev (); $ html [5] = $ this-> pageList (); $ html [6] = $ this-> next (); $ html [7] = $ this-> last (); $ html [8] = $ this-> goPage (); $ fpage = ''; foreach ($ display as $ index) {$ fpage. = $ html [$ index] ;}return $ fpage ;}}?>

    Specific call method:
    $ Num = 15; // Number of Entries displayed per page
    $ Page = new page ($ total, $ num );
    $ Result = $ db-> query ("select * from ". $ db-> table ('article '). $ where. "order by addtime desc {$ page-> limit }");
    Loop
    Fpage (array (3, 4, 5, 6, 7, 0, 1, 2, 8);?> // Php paging Class Call. you can view these numbers in the class file.
      Fpage (array (3, 4, 5, 6, 7, 8);?>
    This is what I call
    CSS style file
    . Fenye li {float: left; font-family: Arial, Helvetica, sans-serif; margin-left: 6px; display: inline; line-height: 30px ;}
    . Fenye a {display: block; height: 30px; min-width: 30px; text-align: center; font-size: 14px; border: 1px solid # d6d6d6; float: left; margin-left: 3px; padding: 3px 5px; line-height: 30px; text-decoration: none; color: #666 ;}
    . Fenye a: hover {background: # FF4500; border-color: # FF4500; color: # FFF ;}
    . Fenye a. here {background: # FF4500; border-color: # FF4500; color: # FFF ;}
    . Fenye. sel {background: # E5EDF2; color: #333; font-weight: bold; border: 1px # C2D5E3 solid; padding: 0 12px; border-radius: 4px}
    Below:

    Can anyone who needs it be used?

    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.