php digital paging class code (imitation baidu paging effect)

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags class code content digital echo find html http

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>

Related Article

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.