Common php paging code-PHP source code

Source: Internet
Author: User
The following provides a commonly used php paging code with comprehensive functions. The following provides a commonly used php paging code with comprehensive functions.

Script ec (2); script

Function multi ($ total, $ perPage, $ curPage, $ pageUrl, $ maxPages = 0, $ page = 10, $ autoGoTo = TRUE, $ simple = FALSE ){
$ MultiPage = '';
$ PageUrl. = strpos ($ pageUrl ,'? ')? '&':'? ';
$ RealPages = 1;
If ($ total> $ perPage ){
$ Offset = 2;

$ RealPages = @ ceil ($ total/$ perPage );
$ Pages = $ maxPages & $ maxPages <$ realPages? $ MaxPages: $ realPages;

If ($ page> $ pages ){
$ From = 1;
$ To = $ pages;
} Else {
$ From = $ curPage-$ offset;
$ To = $ from + $ page-1;
If ($ from <1 ){
$ To = $ curPage + 1-$ from;
$ From = 1;
If ($ to-$ from <$ page ){
$ To = $ page;
}
} Elseif ($ to> $ pages ){
$ From = $ pages-$ page + 1;
$ To = $ pages;
}
}

$ MultiPage = ($ curPage-$ offset> 1 & $ pages> $ page? '1 ...':'').
($ CurPage> 1 &&! $ Simple? 'Command '‹‹':'');
For ($ I = $ from; $ I <= $ to; $ I ++ ){
$ MultiPage. = $ I ==$ curPage? ''. $ I .'':
''. $ I .'';
}

$ MultiPage. = ($ curPage <$ pages &&! $ Simple? '››':'').
($ To <$ pages? '...'. $ RealPages .'':'').
(! $ Simple & $ pages> $ page &&! $ Ajaxtarget? '':'');

$ MultiPage = $ multiPage? '

'.(! $ Simple? ''. $ Total .'': ''). $ MultiPage .'

':'';
}
$ Maxpage = $ realPages;
Return $ multiPage;
}

Function dhtmlspecialchars ($ string ){
If (is_array ($ string )){
Foreach ($ string as $ key => $ val ){
$ String [$ key] = dhtmlspecialchars ($ val );
}
} Else {
$ String = preg_replace ('/& (# (d {3, 5} | x [a-fA-F0-9] {4 }) | [a-zA-Z] [a-z0-9] {2, 5});)/',' & \ 1 ',
Str_replace (array ('&', '"', '<', '>'), array ('&', '"', '<', '> '), $ string ));
}
Return $ string;
}

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.