Classic PHP Paging code (supports digital offset) (1/2)

Source: Internet
Author: User
Tags prev
The code is as follows Copy Code
<style type= "Text/css" >
<!--
Body {
width:800px;
margin:0 Auto;
margin-top:50px;
font-size:12px;
}
A
Color: #014ccc;
Text-decoration:none;
}
. div {
Float:left;
Cursor:pointer;
Font-weight:bold;
margin-right:5px;
Display:block;
PADDING:3PX 7px;
Text-align:center;
border: #bbdded solid 1px;
}
. divs {
Float:left;
Font-weight:bold;
margin-right:5px;
Display:block;
PADDING:3PX 7px;
Text-align:center;
border: #cccccc solid 1px;
}
. divsi {
Float:left;
Font-weight:bold;
margin-right:5px;
Display:block;
PADDING:3PX 7px;
Text-align:center;
Background: #3399ff;
Color: #ffffff;
border: #cccccc solid 1px;
}
. div:hover {
Background: #3399ff;
Color: #ffffff;
}
. divsi:hover {
Background: #3399ff;
Color: #ffffff;
}
-->

</style>

The code is as follows Copy Code

<?php
mysql_connect (' localhost ', ' root ', ');
mysql_select_db (' News ');
mysql_query (' Set names GBK ');

$sql = mysql_query ("select * from ' V_char '");
$num = mysql_num_rows ($sql);
Include ' page.class.php ';
/* Parameter Description:
*getpages ($pagesize, $pagenum, $page, $init, $page _len);
* $pagesize per page record
* Total number of $pagenum records
* $page $_get[page]
* $init The minimum number of paging, the default is 1, generally do not have to change.
* $page number of _len digital paging.
*/
$model = new GetPages (ten, $num, $_get[' page ');

$sql = "SELECT * from ' V_char ' limit $model->offset, $model->pagesize";
$res = mysql_query ($sql);
while ($row = Mysql_fetch_assoc ($res))
{
echo $row [' ID ']. " - " . $row [' name ']. ' <br> ';
}

Output paging information
echo $model->getpage ();
?>

page.class.php

<?php
/*
* Author: Chen Kai
* DATA:2010-09-14
*/
Class GetPages
{
Public $pagesize; Record per page
Public $offset; Number of start records
Public $pagenum; Total Records
Public $page; Current page number
Public $init; Digital pagination leftmost number
Public $page _len; Digital pagination Rightmost number
Public $pages; Total pages

Initialize the assignment.
function __construct ($pagesize, $pagenum, $page, $init =1, $page _len=7)
{
$this->pagesize = $pagesize;//per page record
$this->pagenum = $pagenum; Total Records
$this->page = $page;
$this->pages = ceil ($this->pagenum/$this->pagesize); Total pages
if (Empty ($this->page) | | $this->page <1 | | $this->page > $this->pages) $this->page=1;
$this->init = $init; Digital paging left
$this->page_len = $page _len;//Digital Paging right
$this->offset = ($this->page-1) * $this->pagesize;
}

Output page Paging
function GetPage ()
{
$this-&GT;PREPG = $this->page-1; Previous page
$this->nextpg= ($this->page = = $this->pages)?  0: $this->page+1; Next page
if ($this->pages = = 1) return false; If only one page jumps out
$pagenav = "<span class= ' divs ' >". $this->pages. " Page ". $this->pagenum." Article </span> ";
if ($this->page = = 1)
{
$pagenav. = "<a href= ' # ' class= ' div ' > Home </a>";
$pagenav. = "<a href= ' # ' class= ' div ' > prev </a>";
}
Else
{
$pagenav. = "<a href= '". $this->get_url (). " =1 ' class= ' div ' > Home </a> ';
$pagenav. = "<a href= '". $this->get_url (). " = ". $this->prepg." ' class= ' div ' > prev </a> ';
}

$pagenav. = $this->getvalpage (); Digital paging

if ($this->page = = $this->pages)
{
$pagenav. = "<a href= ' # ' class= ' div ' > next page </a>";
$pagenav. = "<a href= ' # ' class= ' div ' > Last </a>";
}
Else
{
$pagenav. = "<a href= '". $this->get_url (). " = ". $this->nextpg." ' class= ' div ' > Next </a> ';
$pagenav. = "<a href= '". $this->get_url (). " = ". $this->pages." ' class= ' div ' > Last </a> ';
}

Home 1 2 last page

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.