php tutorial digital paging class code (imitation baidu paging effect) This is a php paging program, a digital paging code, much like search engine baidu paging effect Oh.
$ url = $ _ server ['request_uri']; $ url = parse_url ($ url); $ url = $ url [path]; $ sql = "select * from liuyan"; $ query = mysql_query ($ sql); $ num = mysql_num_rows ($ query); // The total number of data $ pagesize = 3; / / set the number of pages per page $ pages = intval ($ num / $ pagesize); // find the approximate number of pages if ($ num% $ pagesize) { $ pages ++; / / Find specific pages }
$ page = 1; // initial page number is 1
if ($ _ get [page]) { $ page = $ _ get [page]; } $ fistpage = 1; // The first page $ prepage = $ page-1; // Previous $ lastpage = $ pages; // last page $ nextpage = $ page + 1; // next page $ n = 1; // page first page $ pack = 1; $ perpage = intval ($ pages / 5); // find the approximate number of pages if ($ pages% 5) { $ perpage ++; } if ($ page> 1) { echo "<a href=$url?page=$fistpage> first page </a>"; echo "<a href=$url?page=$prepage> previous page </a>"; } if ($ page- $ pack> = 5) { $ n ++; $ pack + = 5; $ ($ n * 5-4); $ i <$ page; $ i ++) {// the page before the current page echo "<a href=$url?page=$i> $ i </a>"; } Echo $ i; / / shows the current page if ($ n <$ perpage) { for ($ i = $ i + 1; $ i <= $ n * 5; $ i ++) // the page after the current page echo "<a href=$url?page=$i> $ i </a>"; } else { for ($ i = $ i + 1; $ i <= $ pages; $ i ++) // The page after the current page echo "<a href=$url?page=$i> $ i </a>"; }
} else { for ($ i = ($ n * 5-4); $ i <$ page; $ i ++) // Previous Page Previous Page echo "<a href=$url?page=$i> $ i </a>"; Echo $ i; / / shows the current page if ($ n <$ perpage) { for ($ i = $ i + 1; $ i <= $ n * 5; $ i ++) // the page after the current page echo "<a href=$url?page=$i> $ i </a>"; } else { for ($ i = $ i + 1; $ i <= $ pages; $ i ++) // The page after the current page echo "<a href=$url?page=$i> $ i </a>"; }
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.