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> ';}?>