PHP implements simple paging principles, making it easier to understand!

Source: Internet
Author: User

I recently wrote a website on my own and used paging. After reading many paging principles on the internet, I think they seem to be too complicated to write, which makes it hard for beginners to understand, I wrote a page based on some other people's code and my own ideas. Of course, this is a simple and lightweight page. If you have any features, you can add them on your own. If you think that the writing is not good, please give me more advice and you will be sure to listen carefully!

<? PHP/********************************** paging principle *** * ********************************* // display on each page number of records $ page_size = 3; $ SQL = "select * From message"; $ result = mysql_query ($ SQL );
// Total number of records $ num = mysql_num_rows ($ result); // calculate the total number of pages if ($ num <= $ page_size) {$ page_count = 1 ;} if ($ num % $ page_size) {$ page_count = intval ($ num/$ page_size) + 1;} if ($ num % $ page_size = 0) {$ page_count = $ num/$ page_size;} If (isset ($ _ Get ['page']) {$ page = intval ($ _ Get ['page']);} else {$ page = 1;} $ SQL _page = "select * From message limit ". ($ page-1) * $ page_size. ", $ page_size"; $ DO = mysql_query ($ SQL _page); While ($ Re = My SQL _fetch_object ($ do) {echo 'anything can be written casually ';} if ($ page <> 1) {echo' <a href = "? Page = '. ($ page_count/$ page_count).' "> homepage </a> '; echo' <a href = "? Page = '. ($ page-1 ). '"> previous page </a>';} if ($ page <> $ page_count) {echo '<Div class =" rpage "> '; echo '<a href = "? Page = '. ($ page + 1).' "> next page </a> '; echo' <a href = "? Page = '. ($ page_count).' "> last night </a> '; echo' </div> ';}?>

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.