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]
'; // 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