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.
$ conn = mysql tutorial _connect ("localhost", "root", "");
$ db = mysql_select_db ("gan");
mysql_query ("set names 'gbk'");
?>
<! doctype html public "- // w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.jzread.com/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text / html; charset = gb2312" />
<title> Untitled Document </ title>
</ head>
<body>
<? php
$ 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>";
}
}
if ($ page <$ pages) {
echo "<a href=$url?page=$nextpage> Next page </a>";
echo "<a href=$url?page=$lastpage> last page </a>";
}
$ offnum = ($ page-1) * $ pagesize;
$ fsql = "select * from liuyan limit $ offnum, $ pagesize";
$ query = mysql_query ($ fsql);
while ($ row = mysql_fetch_array ($ query)) {
echo "<br>". $ row [user]. "|". $ row [content];
}
?>
</ body>
</ html>