The pagination effects of numbers and text in PHP self-training projects are implemented in functions,

Source: Internet
Author: User

The pagination effects of numbers and text in PHP self-training projects are implemented in functions,


/***** @ Param $ _ SQL * @ param $ _ size */function _ page ($ _ SQL, $ _ size) {// obtain all the variables in the Table. Externally, you can access global $ _ page, $ _ pagesize, $ _ pagenum, $ _ pageabsolute, $ _ num; if (isset ($ _ GET ['page']) {$ _ page = $ _ GET ['page']; if (empty ($ _ page) | $ _ page <0 |! Is_numeric ($ _ page) {$ _ page = 1;} else {$ _ page = intval ($ _ page) ;}} else {$ _ page = 1 ;} $ _ pagesize = $ _ size; $ _ num = _ num_rows (_ query ($ _ SQL); if ($ _ num = 0) {$ _ pageabsolute = 1;} else {$ _ pageabsolute = ceil ($ _ num/$ _ pagesize);} if ($ _ page> $ _ pageabsolute) {$ _ page =$ _ pageabsolute;} $ _ pagenum = ($ _ page-1) * $ _ pagesize ;} /*** _ paging function * @ param $ _ type * @ return returns pagination */function _ pag Ing ($ _ type) {global $ _ page, $ _ pageabsolute, $ _ num; if ($ _ type = 1) {echo '<div id = "page_num">'; echo '<ul>'; for ($ I = 0; $ I <$ _ pageabsolute; $ I ++) {if ($ _ page = ($ I + 1) {echo '<li> <a href = "blog. php? Page = '. ($ I + 1 ). '"class =" selected "> '. ($ I + 1 ). '</a> </li>';} else {echo '<li> <a href = "blog. php? Page = '. ($ I + 1 ). '"> '. ($ I + 1 ). '</a> </li>';} echo '</ul>'; echo '</div>';} elseif ($ _ type = 2) {echo '<div id = "page_text">'; echo '<ul>'; echo '<li> '. $ _ page. '/'. $ _ pageabsolute. 'page | </li>'; echo '<li> total <strong> '. $ _ num. '</strong> Members | </li>'; if ($ _ page = 1) {echo '<li> homepage | </li> '; echo '<li> Previous Page | </li>';} else {echo '<li> <a href = "'. SCRIPT. '. php "> homepage </a> | </li> '; echo' <li> <a href = "'. SCRIPT. '. ph P? Page = '. ($ _ page-1 ). '"> previous page </a >|</li>';} if ($ _ page ==$ _ pageabsolute) {echo '<li> next page | </li>'; echo '<li> last page </li> ';} else {echo '<li> <a href = "'. SCRIPT. '. php? Page = '. ($ _ page + 1 ). '"> next page </a> | </li>'; echo '<li> <a href = "'. SCRIPT. '. php? Page = '. $ _ pageabsolute. '"> last page </a> </li>';} echo '</ul>'; echo '</div> ';}}

Wrap the above Code glob. funic. php In the core function library

Then, you only need to call the following functions in the file:

<? Php}
// _ Pageing function call page, 1 | 2, 1 indicates the number page, 2 indicates the text page
_ Paging (2 );
?>

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.