The paging function automatically identifies additional link jump parameters.

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn that the paging function in TP will convert the GET link by default. Therefore, some Chinese characters may encounter errors when passing values, write the following functions, without changing the link mode, and append the jump parameters.
/*
* Data Paging
* Parameter $ count number of data entries $ row number of calls
* Return Value
* $ Array [limit] SQL coordinates
* $ Array ['page'] coordinate of the paging Link
*/
Function page ($ count, $ row ){
If (! $ Count) {return '';} // empty data will pop out
$ Url = $ _ SERVER ["REQUEST_URI"]; // read the link
$ Page = $ _ GET ['page']? $ _ GET ['page']: 1; // read the page Coordinate
$ Acount = $ count; // number of data entries
$ Pcount = ceil ($ acount/$ row); // Number of pages divided
$ Url = $ _ GET ['page']? Str_replace (array ('/page /'. $ _ GET ['page'], '& page = '. $ _ GET ['page']), '', $ url): $ url; // remove the page Parameter
$ Limit = ($ page-1) * $ row. ','. $ row; // call limit
$ Pagetpl ='

[Info]

    [First] [link] [end]
'; // Link coordinate Template

// Link Template
If (strstr ($ url, '&') | strstr ($ url, '= ')){
$ Url = $ url. '& page = [url]';
Cancelseif(substr({url,-5}{'.html '){
$ Url = substr ($ url, 0,-5). '/page/[url#.html ';
} Else {
$ Url = $ url. '/page/[url]';
}

// Information
$ Info = 'Total'. $ acount. 'Information'. $ page. '/'. $ pcount. 'page ';

// Page 1
$ First = ($ page! = 1 )? '
  • Page 1
  • ':'';

    // Last page
    $ End = ($ page! = $ Pcount )? '
  • Last page
  • ':'';

    // Previous Page
    $ Prev = ($ page-1) <1? '': $ Page-1;
    $ Prev = $ prev? '
  • Previous Page
  • ': $ Prev;

    // Next page
    $ Next = ($ page + 1)> $ pcount? '': $ Page + 1;
    $ Next = $ next? '
  • Next Page
  • ': $ Next;

    // Link coordinates
    $ Pagelist = '';
    For ($ I = 1; $ I <$ pcount + 1; $ I ++ ){
    If ($ I = $ page ){
    $ Pagelist. ="
  • $ I
  • ";
    } Else {
    $ Pagelist. ="
  • $ I
  • ";
    }
    }
    $ Pagelist = $ prev. $ pagelist. $ next;
    $ Pagelist = ($ pcount> 1 )? $ Pagelist :'';
    $ Show = str_replace ('[info]', $ info, $ pagetpl );
    $ Show = str_replace ('[first]', $ first, $ show );
    $ Show = str_replace ('[link]', $ pagelist, $ show );
    $ Show = str_replace ('[end]', $ end, $ show );

    $ R ['page'] = $ show;
    $ R ['limit'] = $ limit;
    Return $ r;
    }
    Call method TP framework $M = M('article');
    $page = page($M->where($w)->count(),25);
    $list = $M->where($w)->order('wd_px desc,wd_id desc')->limit($page['limit'])->select();
    $this->assign('page',$page['pages']);
    $this->assign('list',$list);
    This method is not limited to TP and is applicable to all PHP programs.
    Original post http://www.90coder.com/Home/Index/article/tid/46.html

    AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

    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.