Common PHP paging

Source: Internet
Author: User
PHP Generic paging php Generic paging, first look at the style

The code is as follows:

 0? Intval ($ page): 1; $ conn = mysql_connect ("127.0.0.1", "root", "") or die ('database connection failed'); mysql_select_db ("demo ", $ conn); mysql_query ("set names UTF8"); $ pageSize = 10; // data displayed on each page $ showPage = 5; // Display Page number $ SQL = "select * from demo limit ". ($ page-1) * $ pageSize. ",". $ pageSize; $ result = mysql_query ($ SQL, $ conn); echo'

'; Echo' '; While ($ row = mysql_fetch_assoc ($ result) {echo' '; Echo' '; Echo' '; Echo' ';} Echo'
ID NAME
'. $ Row ['id'].''. $ Row ['name'].'

'; Mysql_free_result ($ result); $ total_ SQL = "select count (*) from demo"; $ total_result = mysql_fetch_array (mysql_query ($ total_ SQL )); $ total = $ total_result [0]; // calculate the total number of pages $ total_page = ceil ($ total/$ pageSize); mysql_close ($ conn ); /* pagination Bar */$ page_banner ='

'; // Offset $ pageOffset = ($ showPage-1)/2; if ($ page> 1) {$ page_banner. = 'homepage'; $ page_banner. =' < <上一页 ';} else { $page_banner .="<<上一页" ; ;} page start 初始化数据$start="1;$end" = $total_page;if ($total_page> $ ShowPage) {if ($ page> $ pageOffset + 1) {$ page_banner. = '... ';} if ($ page> $ pageOffset) {// the start position is always the current page-offset $ start = $ page-$ pageOffset; // when the display code and offset on the right are less than the total number of pages, the current page + offset is displayed. Otherwise, the last page $ end = $ total_page> ($ page + $ pageOffset) is displayed )? ($ Page + $ pageOffset): $ total_page;} else {$ start = 1; $ end = $ total_page> $ showPage? $ ShowPage: $ total_page;} if ($ page + $ pageOffset> $ total_page) {// actual start position-(current position + offset-last page) $ start = $ start-($ page + $ pageOffset-$ end) ;}}for ($ I = $ start; $ I <=$ end; $ I ++) {if ($ page = $ I) {$ page_banner. = ''. $ I. '';} else {$ page_banner. = ''. $ I. ''; }} if ($ total_page> $ showPage & $ total_page> $ page + $ pageOffset) {$ page_banner. = '... ';} // page endif ($ page <$ total_page) {$ page_banner. = 'next page> '; $ page_banner. = 'Last page';} else {$ page_banner. = 'next page> '; $ page_banner. = 'end page';} $ page_banner. = 'col '. $ total_page. 'Page'; $ page_banner. = 'to

'; Echo $ page_banner;

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.