Php: how to locate all data pagination in the old system _ PHP Tutorial

Source: Internet
Author: User
Php solves the problem of identifying all data paging classes in the old system. Added several custom methods for extracting specified fragments from the mysqlresult set, the reason why no call is released is involved in the original verification of the program. thanks to the help of the online experts, several custom methods for extracting specified fragments from the mysql result set are added, the reason for not calling release 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.

The code is as follows:


/* 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 'Ajax _ func_name. '(\''. $ page. '\''. $ parameter. ') "href =" javascript: void (0) "> '. $ text. ''. "\ n ";
Break;
Case 'html ':
$ Url = str_replace ('? ', $ Page, $ this-> parameter );
Return ''. $ text.''. "\ n ";
Break;
Default:
Return '_ get_url ($ page).' "> '. $ text.'." \ 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. = "$ I \ n ";
}
Else
{
If ($ this-> now_page-$ I >=4 & $ I! = 1)
{
$ Return. = "... \ n ";
$ I = $ this-> now_page-3;
}
Else
{
If ($ I >=$ this-> now_page + 5 & $ I! = $ This-> total_pages)
{
$ Return. = "... \ 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. = "$ I \ 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. ='';
$ Return. = $ this-> first_page (). "\ n ";
$ Return. = $ this-> up_page (). "\ n ";
$ Return. = $ this-> down_page (). "\ n ";
$ Return. = $ this-> last_page (). "\ n ";
$ Return. ='';For ($ I = $ begin; $ I <= $ begin + 10; $ I ++){If ($ I> $ this-> total_pages){Break;}If ($ I ==$ this-> now_page){$ Return. =''. $ I .'';}Else{$ Return. =''. $ I .'';}}$ Return. ='';
Return $ return;
}
}
?>

Pipeline extracts the specified part from the mysql result set. the reason for not calling the release is that the original verification of the program is also thanks to the help of the online experts...

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.