Php solves the problem of identifying all data paging classes in the old system

Source: Internet
Author: User

Added several custom methods for extracting specified fragments from the mysql result set. The reason for not calling the release is that it involves the original verification of the program.
Thanks to the help of the online experts .... The old system kills people, and the background cannot be moved. Copy codeThe Code is as follows: <? Php
/* Paging class
* @ Author xiaojiong & 290747680@qq.com
* @ Date 2011-08-17
*
* Show (2) 1... 62 63 64 65 66 67 68... 150
* Paging Style
* # Page {font: 12px/16px arial}
* # Page span {float: left; margin: 0px 3px ;}
* # Page a {float: left; margin: 0 3px; border: 1px solid # ddd; padding: 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; // The start row.
Public $ list_rows; // The number of lines displayed on each page in the list
Protected $ total_pages; // total number of pages
Protected $ total_rows; // total number of rows
Protected $ now_page; // current page number
Protected $ method = 'delete'; // processing Ajax paging Html paging (static) normal get Mode
Protected $ parameter = '';
Protected $ page_name; // name of the paging Parameter
Protected $ ajax_func_name;
Public $ plus = 3; // page 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 the 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 url of $ page.
* @ Param $ 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;
}
/**
* The first page is displayed.
* @ Return string
*/
Public function first_page ($ name = 'page 1 ')
{
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 = 'previous page ')
{
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 '';
}
/**
* Paging 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. 'records are classified '. $ this-> total_pages. 'page, current '. $ this-> now_page. 'page ';
$ Return. = ', each 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.