Classic php paging code (supporting digital offset) (1/2)-PHP source code

Source: Internet
Author: User
This php paging code is a complete and classic paging function of phpmysqlcss. It is suitable for forums such as phpwindowdz. This php paging code is a complete and classic paging function of php mysql css. It is suitable for forums such as phpwindow dz.

Script ec (2); script

The Code is as follows:

The Code is as follows:

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 records per page
* $ Total number of pagenum records
* $ Page $ _ get [page]
* $ Init: Minimum number of numeric pages. The default value is 1, which is generally not changed.
* $ Page_len: Number of pagination pages.
*/
$ Model = new getpages (10, $ 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'].'
';
}

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

Page. class. php

/*
* Author: Chen Kai
* Data: 2010-09-14
*/
Class getpages
{
Public $ pagesize; // record per page
Public $ offset; // number of start records
Public $ pagenum; // total record
Public $ page; // the current page number.
Public $ init; // The leftmost number of The number page
Public $ page_len; // the rightmost number of The number page
Public $ pages; // the total number of pages.

// Initialize the value assignment.
Function _ construct ($ pagesize, $ pagenum, $ page, $ init = 1, $ page_len = 7)
{
$ This-> pagesize = $ pagesize; // records per page
$ This-> pagenum = $ pagenum; // total record
$ This-> page = $ page;
$ This-> pages = ceil ($ this-> pagenum/$ this-> pagesize); // total number of pages
If (empty ($ this-> page) | $ this-> page <1 | $ this-> page> $ this-> pages) $ this-> page = 1;
$ This-> init = $ init; // left-side numeric Paging
$ This-> page_len = $ page_len; // right of the number page
$ This-> offset = ($ this-> page-1) * $ this-> pagesize;
}

// Output page
Function getpage ()
{
$ This-> 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 exists
$ Pagenav = "Total". $ this-> pages. "Page". $ this-> pagenum. "bar ";
If ($ this-> page = 1)
{
$ Pagenav. = "Homepage ";
$ Pagenav. = "Previous Page ";
}
Else
{
$ Pagenav. = "get_url ()." = 1 'class = 'P'> Homepage ";
$ Pagenav. = "get_url ()." = ". $ this-> prepg." 'class = 'P'> previous page ";
}

$ Pagenav. = $ this-> getvalpage (); // numeric Paging

If ($ this-> page ==$ this-> pages)
{
$ Pagenav. = "next page ";
$ Pagenav. = "last page ";
}
Else
{
$ Pagenav. = "get_url ()." = ". $ this-> nextpg." 'class = 'P'> next page ";
$ Pagenav. = "get_url ()." = ". $ this-> pages." 'class = 'P'> last page ";
}

Homepage 1 2 last

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.