Module paging-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;? PhpPHP code: & lt ;? Php $ page_infocount_page ($ total, PER_PAGE); paging Parameters & nbsp; $ smarty-& gt; assign (page_first, $ page_info [page_first]); & nbsp; $ smarty-& gt; assign (page_last, $ page_ I script ec (2); script

PHP code:

$ Page_info = count_page ($ total, PER_PAGE); // page Parameters
$ Smarty-> assign ('page _ first ', $ page_info ['page _ first']);
$ Smarty-> assign ('page _ last', $ page_info ['page _ last']);
$ Smarty-> assign ('page _ str', $ page_info ['page _ str']);
$ SQL = "SELECT * FROM 'News' ORDER BY 'id' DESC LIMIT {$ page_info ['offset']},". PER_PAGE;
?>


// PAGE: $ total PAGE size $ per number of items displayed per PAGE $ show list items
Function count_page ($ total = 0, $ per)
{
$ Page_out = array (
'Page _ first' => '', // Homepage
'Page _ last' => '', // last page
'Page _ str' => '', // pagination
'Now _ page' => 1, // current page
'Offset' => 0, // offset
);
$ Page_count = ceil ($ total/$ per); // total number of pages
If ($ page_count <= 1 ){
Return $ page_out;
}
$ Page_out ['now _ page'] = @ $ _ GET ['page'] + 0;
If ($ page_out ['now _ page'] <1 ){
$ Page_out ['now _ page'] = 1;
} Elseif ($ page_out ['now _ page']> $ page_count ){
$ Page_out ['now _ page'] = $ page_count;
}

$ Page_out ['offset'] = ($ page_out ['now _ page']-1) * $ per;
// URL regular
$ SELF = "[url = http: // {$ _ SERVER [] http: // {$ _ SERVER ['HTTP _ host']} {$ _ SERVER ['php _ SELF '[/url]}? ";
@ $ QUERY = $ _ SERVER ['query _ string'];
$ Query_page = preg_replace (array ("! (& | ^) Page = ([^ &] +) | (page = )! ","! (^ &) | [&] {2,} | ([&] $ )! "), Array ('', ''), $ QUERY );
$ Query_page = $ SELF. $ query_page. ($ query_page? "&":"");
/* First page */
$ Page_out ['page _ first'] = '1 ';
If ($ page_out ['page _ first'] = $ page_out ['now _ page']) {
$ Page_out ['page _ first'] ='

  • < <首页< li> ';
    } Else {
    $ Page_out ['page _ first'] ='
  • < <首页< li> ';
    }
    /* Last page */
    $ Page_out ['page _ last'] = $ page_count;
    If ($ page_out ['page _ last'] = $ page_out ['now _ page']) {
    $ Page_out ['page _ la'] ='
  • Last page>
  • ';
    } Else {
    $ Page_out ['page _ la'] ='
  • Last page>
  • ';
    }
    // The limit page is-2 Edit.
    $ Pageleft = $ page_out ['now _ page']> = 4? $ Page_out ['now _ page']-4: 1;
    $ Pageright = $ page_out ['now _ page'] + 4 <= $ page_count? $ Page_out ['now _ page'] + 4: $ page_count;

    For ($ I = $ pageleft; $ I <= $ pageright; $ I ++ ){
    If ($ I = $ page_out ['now _ page']) {
    $ Page_out ['page _ str']. ='

  • '. $ I .'
  • ';
    } Else {
    $ Page_out ['page _ str']. ='
  • '. $ I .'
  • ';
    }
    }
    Return $ page_out;
    }
    ?>


    Copy the PHP content to the clipboard.
    PHP code:
    CSS file

    /* PAGE */
    # Page li {border: 0; margin: 0; padding: 0; font-size: 11px; list-style: none;/* savers */float: left ;}
    # Page a {border: solid 1px #9aafe5; margin-right: 2px ;}
    # Page. previous-off, # page. next-off {border: solid 1px # DEDEDE; color: #888888; display: block; float: left; font-weight: bold; margin-right: 2px; padding: 3px 4px ;}
    # Page. next a, # page. previous a {font-weight: bold ;}
    # Page. active {background: #2e6ab1; color: # FFFFFF; font-weight: bold; display: block; float: left; padding: 4px 6px;/* savers */margin-right: 2px ;}
    # Page a: link, # page a: visited {color: # 0e509e; display: block; float: left; padding: 3px 6px; text-decoration: none ;}
    # Page a: hover {border: solid 1px # 0e509e ;}

    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.