PHP to solve the old system to detect all data paging class _php instance

Source: Internet
Author: User
Added several custom methods for extracting the specified fragment from the MySQL result set, and the reason for not invoking the release is that this involves the original checksum of the program
Thanks to the help of the great God on the Internet .... The old system kills people, they can't move backstage.
Copy Code code as follows:

<?php
/* Pagination Class
* @author Xiaojiong & 290747680@qq.com
* @date 2011-08-17
*
* Show (2) 1 ... 62 63 64 65 66 67 68 ... 150
* Pagination Style
* #page {font:12px/16px arial}
* #page span{float:left;margin:0px 3px;}
* #page a{float:left;margin:0 3px;border:1px solid #ddd;p adding:3px 7px; Text-decoration:none;color: #666}
* #page a.now_page, #page a:hover{color: #fff; background: #05c}
*/
Class Core_lib_page
{
Public $first _row; Number of rows to start
Public $list _rows; The list shows the number of rows per page
protected $total _pages; Total pages
protected $total _rows; Total number of rows
protected $now _page; Current page
protected $method = ' Defalut '; Handling situations Ajax Paging HTML Paging (static) General Get method
protected $parameter = ';
protected $page _name; The name of the paging parameter
protected $ajax _func_name;
Public $plus = 3; Paging offset
protected $url;
Public Function Get_page_result ()
{
$lastResult = Array ();
$skipCount = $this->get_skip_row_count ();
if (mysql_num_rows ($result) >0)
{
Mysql_data_seek ($result, $skipCount);
}
$pageSize = $this-> $list _rows;
while ($row = Mysql_fetch_array ($result))
{
$pageSize--;
$lastResult [] = $row;
if ($pageSize = = 0)
{
break;
}
}
return $lastResult;
}
Public Function Get_skip_row_count ()
{
return $this->list_rows* ($this->now_page-1);
}
/**
* Constructor
* @param unknown_type $data
*/
Public function __construct ($data = Array ())
{
$this->total_rows = $data [' total_rows '];
$this->parameter =!empty ($data [' parameter '])? $data [' parameter ']: ';
$this->list_rows =!empty ($data [' list_rows ']) && $data [' list_rows '] <= 100? $data [' List_rows ']: 15;
$this->total_pages = ceil ($this->total_rows/$this->list_rows);
$this->page_name =!empty ($data [' page_name '])? $data [' page_name ']: ' P ';
$this->ajax_func_name =!empty ($data [' ajax_func_name '])? $data [' Ajax_func_name ']: ';
$this->method =!empty ($data [' method '])? $data [' method ']: ';
/* Current Page/*
if (!empty ($data [' now_page '])
{
$this->now_page = intval ($data [' now_page ']);
}else{
$this->now_page =!empty ($_get[$this->page_name])? Intval ($_get[$this->page_name]): 1;
}
$this->now_page = $this->now_page <= 0? 1: $this->now_page;
if (!empty ($this->total_pages) && $this->now_page > $this->total_pages)
{
$this->now_page = $this->total_pages;
}
$this->first_row = $this->list_rows * ($this->now_page-1);
}
/**
* Get Current connection
* @param $page
* @param $text
* @return String
*/
protected function _get_link ($page, $text)
{
Switch ($this->method) {
Case ' Ajax ':
$parameter = ';
if ($this->parameter)
{
$parameter = ', '. $this->parameter;
}
Return ' <a onclick= '. $this->ajax_func_name. ' (\ '. $page. '. $parameter. ') href= "javascript:void (0)" > ". $text. ' </a> '. "\ n";
Break
Case ' HTML ':
$url = Str_replace ('? ', $page, $this->parameter);
Return ' <a href= '. $url. ' > '. $text. ' </a> '. "\ n";
Break
Default
Return ' <a href= '. $this->_get_url ($page). ' > '. $text. ' </a> '. "\ n";
Break
}
}
/**
* Set the current page link
*/
protected function _set_url ()
{
$url = $_server[' Request_uri ']. (Strpos ($_server[' Request_uri '], '? ')? ': "?". $this->parameter;
$parse = Parse_url ($url);
if (Isset ($parse [' query '])) {
Parse_str ($parse [' query '], $params);
Unset ($params [$this->page_name]);
$url = $parse [' Path ']. Http_build_query ($params);
}
if (!empty ($params))
{
$url. = ' & ';
}
$this->url = $url;
}
/**
* Get the $page URL
* @param $page Page
* @return String
*/
protected function _get_url ($page)
{
if ($this->url = = NULL)
{
$this->_set_url ();
}
$lable = Strpos (' & ', $this->url) = = FALSE? ': ' & ';
Return $this->url. $this->page_name. '=' . $page;
}
/**
* Get the first page
* @return String
*/
Public Function first_page ($name = ' first page ')
{
if ($this->now_page > 5)
{
return $this->_get_link (' 1 ', $name);
}
Return ";
}
/**
* Last Page
* @param $name
* @return String
*/
Public Function last_page ($name = ' last page ')
{
if ($this->now_page < $this->total_pages-5)
{
return $this->_get_link ($this->total_pages, $name);
}
Return ";
}
/**
* Previous Page
* @return String
*/
Public Function up_page ($name = ' prev ')
{
if ($this->now_page!= 1)
{
return $this->_get_link ($this->now_page-1, $name);
}
Return ";
}
/**
* Next Page
* @return String
*/
Public Function down_page ($name = ' next page ')
{
if ($this->now_page < $this->total_pages)
{
return $this->_get_link ($this->now_page + 1, $name);
}
Return ";
}
/**
* Pagination Style output
* @param $param
* @return String
*/
Public function Show ($param = 1)
{
if ($this->total_rows < 1)
{
Return ";
}
$className = ' Show_ '. $param;
$classNames = Get_class_methods ($this);
if (In_array ($className, $classNames))
{
return $this-> $className ();
}
Return ";
}
protected function show_2 ()
{
if ($this->total_pages!= 1)
{
$return = ';
$return. = $this->up_page (' < ');
for ($i = 1; $i <= $this->total_pages; $i + +)
{
if ($i = = $this->now_page)
{
$return. = "<a class= ' now_page ' > $i </a>\n";
}
Else
{
if ($this->now_page-$i >=4 && $i!= 1)
{
$return. = "<span class= ' Pagemore ' >...</span>\n";
$i = $this->now_page-3;
}
Else
{
if ($i >= $this->now_page+5 && $i!= $this->total_pages)
{
$return. = "<span>...</span>\n";
$i = $this->total_pages;
}
$return. = $this->_get_link ($i, $i). "\ n";
}
}
}
$return. = $this->down_page (' > ');
return $return;
}
}
protected function Show_1 ()
{
$plus = $this->plus;
if ($plus + $this->now_page > $this->total_pages)
{
$begin = $this->total_pages-$plus * 2;
}else{
$begin = $this->now_page-$plus;
}
$begin = ($begin >= 1)? $begin: 1;
$return = ';
$return. = $this->first_page ();
$return. = $this->up_page ();
for ($i = $begin; $i <= $begin + $plus * 2; $i + +)
{
if ($i > $this->total_pages)
{
Break
}
if ($i = = $this->now_page)
{
$return. = "<a class= ' now_page ' > $i </a>\n";
}
Else
{
$return. = $this->_get_link ($i, $i). "\ n";
}
}
$return. = $this->down_page ();
$return. = $this->last_page ();
return $return;
}
protected function Show_3 ()
{
$plus = $this->plus;
if ($plus + $this->now_page > $this->total_pages)
{
$begin = $this->total_pages-$plus * 2;
}else{
$begin = $this->now_page-$plus;
}
$begin = ($begin >= 1)? $begin: 1;
$return = ' total '. $this->total_rows. ' A record is divided into '. $this->total_pages. ' Page, current section '. $this->now_page. ' Page ';
$return. = ', per page ';
$return. = ' <input type= ' text ' value= '. $this->list_rows. ' "id=" PageSize "size=" 3 ">";
$return. = $this->first_page (). \ n ";
$return. = $this->up_page (). \ n ";
$return. = $this->down_page (). \ n ";
$return. = $this->last_page (). \ n ";
$return. = ' <select onchange= '. $this->ajax_func_name. ' (this.value) "id=" GotoPage ">";
for ($i = $begin; $i <= $begin +10; $i + +)
{
if ($i > $this->total_pages)
{
Break
}
if ($i = = $this->now_page)
{
$return. = ' <option selected= true ' value= '. $i. ' > ' $i. ' </option> ';
}
Else
{
$return. = ' <option value= '. $i. ' > ' $i. ' </option> ';
}
}
$return. = ' </select> ';
return $return;
}
}
?>

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.