Paging functions and applications (PHP)

Source: Internet
Author: User

This is a php paging code found on the Internet. It is modified and ready for use at any time,

Paging functions:

<? Php function showpage ($ per, $ all, $ page, $ page_len) // number of records, total number of records, current page, and displayed page number {$ page_total = ceil ($ all/$ per); $ begin = 1; $ end = $ page_total; if ($ page_total> $ page_len) {if ($ page + 4> $ page_total) {$ end = $ page_total; $ begin = $ page_total-8 ;} else if ($ page <= 5) {$ begin = 1; $ end = 9;} else {$ begin = $ page-4; $ end = $ page + 4 ;}} if ($ page! = 1) {$ pagenums = "$ page/$ page_total <a href = \" ". $ _ SERVER ['php _ SELF '].'? Page = 1 "> homepage </a> '; $ pagenums. =" <a href = \ "". $ _ SERVER ['php _ SELF']. "? Page = ". ($ page-1 ). '"> previous page </a>';} else $ pagenums =" $ page/$ page_total previous page "; for ($ I = $ begin; $ I <= $ end; $ I ++) {if ($ page! = $ I) $ pagenums. = '<a href = "'. $ _ SERVER ['php _ SELF ']."? Page = $ I \ "> $ I </a>"; else $ pagenums. = "$ I";} if ($ page = $ page_total) $ pagenums. = "last page of the next page"; else $ pagenums. = "<a href = \"". $ _ SERVER ['php _ SELF ']. "? Page = ". ($ page + 1 ). "\"> next page </a> ". "<a href = \"". $ _ SERVER ['php _ SELF ']. "? Page = $ page_total \ "> last page </a>"; return $ pagenums;}?>

Application:

<? Php include ("showpage. php "); $ link = mysql_connect (" localhost "," root "," "); mysql_select_db (" oj "); mysql_query (" set names utf8 "); $ result = mysql_query ("select * from problem"); $ all = mysql_num_rows ($ result); $ page = $ _ GET ['page']; // if (empty ($ page) | $ page <= 0) $ page = 1; $ page_len = 9; // The displayed page number $ per = 50; // number of records per page $ temp = ($ page-1) * 10; $ SQL = "select * from problem limit $ temp, 10 "; $ result = mysql_query ($ SQL); while ($ row = mysql_fetc H_array ($ result) echo $ row ['title']. "<br>"; echo showpage ($ per, $ all, $ page, $ page_len); // call?>

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.