-
Class PageLink {
- /* Page display parameter settings */
- Private $ db_table = "";
- Private $ db_table_field = ""; // fields in the database to be displayed
- Private $ condition = ""; // query condition
- Private $ sort = ""; // sorting condition
- Private $ page_size = 0; // number of records displayed on each page
- Private $ link_num = 0; // display the number of page number links
- Private $ page = 1; // Current page number
- Private $ records = 0; // total number of records in the table
- Private $ page_count = 0; // total number of pages
- Private $ pagestring = ""; // string of the front and back pagination links
- Private $ linkUrl = ""; // Current page path
- Private $ urlPara = ""; // url parameters of the current page
- Private $ linkUrlNum = 1;
- /*
- * Custom paging
- */
- Private $ linkFormat = "";
-
/* Obtained data */
- Private $ page_data = ""; // data obtained from the database,
-
// $ Page_data is received as a two-dimensional array
-
Private $ dbHelper;
- /* Variable definition part end */
-
/* Function definition (class method) begin */
-
Function _ construct () {include_once 'dbhelper/DBHelper. php'; // This is a database operation class
- $ This-> dbHelper = new DBHelper ();
- }
-
/*
- * Set page information begin
- * @ Param $ db_table
- * @ Param $ db_table_field
- * @ Param $ condition
- * @ Param $ sort
- * @ Param $ page_size displays the number of conditions.
- * @ Param $ link_num number of data records
- * @ Param $ url router interface
- * @ Param $ para url parameters
- */
- Public function set ($ db_table, $ db_table_field, $ condition, $ sort, $ page_size, $ link_num, $ url, $ para ){
- $ This-> db_table = $ db_table; // table name
- $ This-> db_table_field = $ db_table_field; // field array,
- $ This-> condition = $ condition; // sorting condition
- $ This-> sort = $ sort; // sorting condition
- // Name of the field to be displayed
- // Write the array
- /* Set the end of the db parameter */
-
/* Set the paging parameter to begin */
- $ This-> page_size = $ page_size; // number of records displayed on each page
- $ This-> link_num = $ link_num; // display the number of paging links
- $ This-> linkUrl = $ url;
- $ This-> urlPara = $ para;
- /* Set end with paging parameters */
- }
-
/* Set the end of the page information */
-
/* Obtain the paging link data begin */
-
Public function get (){
- $ Page_data [0] = $ this-> pagestring;
- $ Page_data [1] = $ this-> page_data;
- Return $ page_data;
- }
-
/* Get the end of the paging link data */
-
/* Page number processing begin */
-
Private function set_page (){
- If (isset ($ _ REQUEST ["page"]) {
- $ This-> page = intval ($ _ REQUEST ["page"]);
- } Else {
- $ This-> page = 1;
- }
- }
-
/* Page number processing end */
-
/* Obtain the number of records in the database begin */
-
Private function get_records (){
- $ This-> records = $ this-> dbHelper-> counts ($ this-> db_table, $ this-> condition );
- }
-
/* Obtain the number of records in the database. end */
-
/* Create a flip link string begin */
-
Private function page_link (){
- $ CheckPage = intval ($ this-> page/$ this-> link_num );
- $ StartPage = 1;
- $ StopPage = 1;
- If ($ checkPage = 0 & $ this-> page <$ this-> link_num ){
- $ StartPage = 1;
- }
- $ LinkPage = ($ this-> link_num/2 );
- If ($ this-> page> $ linkPage ){
- $ StartPage = $ this-> page-$ linkPage;
- }
- If ($ startPage + $ this-> link_num)> $ this-> page_count ){
- $ StartPage = $ this-> page_count-$ this-> link_num + 1;
- }
- If ($ startPage <1 ){
- $ StartPage = 1;
- }
- $ StopPage = $ startPage + ($ this-> link_num-1 );
- If ($ stopPage> $ this-> page_count ){
- $ StopPage = $ this-> page_count;
- }
- $ CountStr = "total". $ this-> records. "note ";
- $ CurrStr ="". $ This-> page ."/". $ This-> page_count." success ";
- $ BeginLink = "linkUrl ."? Page = 1 ". $ this-> urlPara." '> first vertex ";
- $ PreLink = "linkUrl ."? Page = ". ($ this-> page-1). $ this-> urlPara." '> previous partition ";
- $ NextLink = "linkUrl ."? Page = ". ($ this-> page + 1). $ this-> urlPara." '> next cursor ";
- $ NoPreLink = "previous release ";
- $ NoNextLink = "Next release ";
- $ EndLink = "linkUrl ."? Page = ". $ this-> page_count. $ this-> urlPara." '> tail cursor ";
- If ($ this-> page> ($ linkPage + 1) & $ this-> page_count> $ this-> link_num ){
- $ CurrPage. = "linkUrl ."? Page = 1 ". $ this-> urlPara." '> 1 ";
- }
- For ($ I = $ startPage; $ I <= $ stopPage; $ I ++ ){
- If ($ I ==$ this-> page ){
- $ CurrPage. = "". $ I ."";
- }
- Else {
- $ CurrPage. = "linkUrl ."? Page = ". $ I. $ this-> urlPara." '> ". $ I ."";
- }
- }
- If ($ this-> page_count-$ this-> page)> $ linkPage & $ this-> page_count> $ this-> link_num ){
- $ CurrPage. = "... $ this-> linkUrl ."? Page = ". $ this-> page_count. $ this-> urlPara." '> ". $ this-> page_count ."";
- }
- $ JumpPage. ="";
- $ JumpPage. ="LinkUrl
- ."? Page = '+ document. getElementById ('page _ text _ ". $ this-> linkUrlNum."'). value + '". $ this-> urlPara
- . "'\" Name = 'page _ submit' value = 'go'/> ";
- $ This-> linkUrlNum ++;
- If (! Empty ($ this-> linkFormat )){
- $ TempLinkFormat = $ this-> linkFormat;
- $ TempLinkFormat = str_replace ("president", $ countStr, $ tempLinkFormat );
- $ TempLinkFormat = str_replace ("repeated times", $ currStr, $ tempLinkFormat );
- If ($ this-> page_count> 1 ){
- $ TempLinkFormat = str_replace ("first vertex", $ beginLink, $ tempLinkFormat );
- If ($ this-> page> 1 ){
- $ TempLinkFormat = str_replace ("last updated", $ preLink, $ tempLinkFormat );
- }
- Else {
- $ TempLinkFormat = str_replace ("last updated", $ noPreLink, $ tempLinkFormat );
- }
- If ($ this-> page <$ this-> page_count ){
- $ TempLinkFormat = str_replace ("Next release", $ nextLink, $ tempLinkFormat );
- }
- Else {
- $ TempLinkFormat = str_replace ("Next release", $ noNextLink, $ tempLinkFormat );
- }
- $ TempLinkFormat = str_replace ("last modified", $ endLink, $ tempLinkFormat );
- $ TempLinkFormat = str_replace ("minute into", $ currPage, $ tempLinkFormat );
- $ TempLinkFormat = str_replace ("skip", $ jumpPage, $ tempLinkFormat );
- }
- Else {
- $ TempLinkFormat = str_replace ("first digit", "", $ tempLinkFormat );
- $ TempLinkFormat = str_replace ("last updated", "", $ tempLinkFormat );
- $ TempLinkFormat = str_replace ("Next region", "", $ tempLinkFormat );
- $ TempLinkFormat = str_replace ("tailslate", "", $ tempLinkFormat );
- $ TempLinkFormat = str_replace ("minute", "", $ tempLinkFormat );
- $ TempLinkFormat = str_replace ("skip", "", $ tempLinkFormat );
- }
-
}
- $ This-> pagestring. = $ countStr. "". $ currStr;
- If ($ this-> page_count> 1 ){
- $ This-> pagestring. = $ beginLink;
- If ($ this-> page> 1 ){
- $ This-> pagestring. = $ preLink;
- }
- $ This-> pagestring. = $ currPage;
- If ($ this-> page <$ this-> page_count ){
- $ This-> pagestring. = $ nextLink;
- }
- $ This-> pagestring. = $ endLink. $ jumpPage;
- }
- }
-
/* Create a flip link string end */
-
/* Get data begin */
-
Private function fetch_data (){
- If ($ this-> records ){
- $ Limit = ($ this-> page-1) * $ this-> page_size. ", $ this-> page_size ";
- $ This-> page_data = $ this-> dbHelper-> fetch ($ this-> db_table, $ this-> condition, $ this-> sort, $ limit );
- }
- }
-
/* Get data end */
-
/* Create a page begin */
-
Public function create_page (){
- $ This-> set_page ();
- $ This-> get_records ();
- $ This-> page_count = ceil ($ this-> records/$ this-> page_size );
- $ This-> page_link ();
- $ This-> fetch_data ();
- }
-
/* Create a paging end */
-
Function _ destruct (){
-
}
-
/* Function definition (class method) end */
- }
- /*
- Call method
- Include_once 'pagelink. php ';
- $ PageLink = new PageLink (); // instantiate an object
- $ PageLink-> set ("table", "* (or field)", "condition", "sort", "number of data entries", "number of links per page ", "page (list. php) ","? Other parameters except page = 1 (& id = 1 & name = test) "); // input parameters
- $ PageLink-> create_page (); // Create a page
- $ List = $ pageLink-> get (); // get Data
- Echo $ list [0]; // paging link
- Print_r ($ list [1]); // Print the data, or loop it out as needed
- */
|