The complete page paging module is exactly the same as that of Baidu

Source: Internet
Author: User
Provide a variety of official and user release code examples, code reference, welcome to exchange learning http://www.schoolcms.cn/release
The complete page paging module is exactly the same as that of Baidu

Class PagingModel
{
Private $ m_PagingDataArray; // receives the post or get one-dimensional array conditions submitted on the page.
Private $ m_Configuration; // configuration item data
Private $ m_Fraction; // number of entries displayed on each page
Private $ m_Total; // The total number of data items
Private $ m_Page; // the page number passed by the page
Private $ m_Starting; // start value of the queried data
Private $ m_TotalFraction; // total number of calculated pages
Private $ m_Url; // The url address used for paging
Private $ m_PageCoent; // whether to enable the pagination button


/*
Constructor
*/
Public function _ construct ($ PagingDataArray = array (), $ Configuration = array ())
{
/* Initialize attribute data */
$ This-> m_PagingDataArray = array ();
$ This-> m_Configuration = array ();

/* Basic Data settings */
$ This-> SetPagingDataArray ($ PagingDataArray );
$ This-> SetConfiguration ($ Configuration );
$ This-> SetBasisData ();
}

/*
Set Data
*/
Private function SetPagingDataArray ($ PagingDataArray)
{
/* Determine whether the configuration item data is empty */
If (false = empty ($ PagingDataArray )){
$ This-> m_PagingDataArray = $ PagingDataArray;
} Else {
$ This-> m_PagingDataArray = array ();
}
}

/*
Set Configuration item data
*/
Private function SetConfiguration ($ Configuration)
{
/* Determine whether the configuration item data is empty */
If (false = empty ($ Configuration )){
$ This-> m_Configuration = $ Configuration;
} Else {
$ This-> m_Configuration = array ();
}
}


/*
Processing and determining whether a key name exists in the array
*/
Private function Setuppase ($ Property, $ Key, $ Content)
{
/* Determine whether the $ Key exists in the array */
If (true = array_key_exists ($ Key, $ this-> m_Configuration )){
$ This-> $ Property = $ this-> m_Configuration ["$ Key"];
} Else {
$ This-> $ Property = $ Content;
}
}

/*
Basic Data settings
*/
Private function SetBasisData ()
{
$ This-> SetFraction ();
$ This-> SetTotal ();
$ This-> SetPage ();
$ This-> SetStarting ();
$ This-> SetTotalFraction ();
$ This-> SetUrl ();
$ This-> SetPageCoent ();
}

/*
Set the number of data entries per page
*/
Private function SetFraction ()
{
$ This-> Setuppase ('m _ fraction', 'traction ', 15 );
}

/*
Set the total number of data entries
*/
Private function SetTotal ()
{
$ This-> Setuppase ('m _ total', 'Total', 0 );
}

/*
Set the page number passed by the page
*/
Private function SetPage ()
{
/* Determine whether the $ Key exists in the array */
If (true = array_key_exists ('page', $ this-> m_PagingDataArray )){
$ This-> m_Page = max (1, (false = empty ($ this-> m_PagingDataArray ['page'])? Intval ($ this-> m_PagingDataArray ['page']): 0 ));
} Else {
$ This-> m_Page = 1;
}
}

/*
Set the start value of the queried data
*/
Private function SetStarting ()
{
$ This-> m_Starting = ($ this-> m_Page-1) * $ this-> m_Fraction;
}

/*
Set the calculated total number of pages. Total number of pages = total number of lines divided by the number of lines displayed on each page.
*/
Private function SetTotalFraction ()
{
$ This-> m_TotalFraction = ceil ($ this-> m_Total/$ this-> m_Fraction );

/* When the current page number is greater than the maximum page number, assign the value of the total page number to the current page to avoid exceeding the operation. */
If ($ this-> m_TotalFraction <= $ this-> m_Page ){
$ This-> m_Page = $ this-> m_TotalFraction;
}
}

/*
Set the pagination url
*/
Private function SetUrl ()
{
$ This-> Setuppase ('m _ url', 'url', null );
}

/*
Set whether to enable the "show number pagination" button.
*/
Private function SetPageCoent ()
{
$ This-> Setuppase ('m _ PageCoent ', 'pagecoent', 0 );
}

/*
Obtain the start value of the queried data.
*/
Public function GetStarting ()
{
Return $ this-> m_Starting;
}

/*
Returns the number of entries displayed on each page.
*/
Public function GetFraction ()
{
Return $ this-> m_Fraction;
}

/*
Obtain the number page number displayed on each page.
*/
Private function GetPageCoent ($ PageUrl)
{
/* If the page value is not equal to 1 */
If ($ this-> m_Page! = 1 ){
/* If the page number plus the displayed page number is greater than the current total page number */
If ($ this-> m_Page + $ this-> m_PageCoent)> $ this-> m_TotalFraction ){
/* Calculate the start value */
$ Pageis = $ this-> m_Page-$ this-> m_PageCoent;
/* Calculate the maximum value */
$ PageMax = $ this-> m_TotalFraction;

/* If the page number plus the displayed page number is not greater than the current total page number */
} Else {
/* Calculate the start value. If the current page is smaller than or equal to the number of displayed pages, set the start value to 1 to prevent negative numbers */
If ($ this-> m_Page <= $ this-> m_PageCoent ){
$ Pageis = 1;
} Else {
$ Pageis = $ this-> m_Page-$ this-> m_PageCoent;
}


/* Calculate the maximum value. The current page value is added with the number of pages to be displayed */
$ PageMax = ($ this-> m_Page + $ this-> m_PageCoent ));
}

/* If the displayed page number value is greater than or equal to the total page number value, set the start value to 1 */
If ($ this-> m_PageCoent >=$ this-> m_TotalFraction ){
$ Pageis = 1;
}

/* If the page is equal to 1 */
} Else {
/* If the displayed page number value is greater than or equal to the total page number value, assign the total page number value to the maximum value of the loop */
If ($ this-> m_PageCoent >=$ this-> m_TotalFraction ){
$ PageMax = $ this-> m_TotalFraction;
} Else {
$ PageMax = $ this-> m_PageCoent + 1;
}
$ Pageis = 1;
}

/* Code for the number of paging values to be displayed for loop splicing */
$ PageCoent ='
  • ';
    For ($ Pagei = $ Pageis; $ Pagei <= $ PageMax; $ Pagei ++ ){
    If ($ this-> m_Page = $ Pagei ){
    $ PageCoent. = ''. $ Pagei .'';
    } Else {
    $ PageCoent. = ''. $ Pagei .'';
    }

    }
    /* Return the spliced Code */
    Return $ PageCoent;
    }


    /*
    Obtain url concatenation and process URL concatenation
    */
    Private function GetUrlSplice ()
    {
    $ UrlSplice = '? ';
    If (false = empty ($ this-> m_PagingDataArray )){
    // Delete the page data in the current array
    Unset ($ this-> m_PagingDataArray ['page']);
    Foreach ($ this-> m_PagingDataArray as $ PKey => $ pValue ){
    /* Splice common URLs */
    If (false = empty ($ pValue) & (false = is_array ($ pValue ))){
    $ UrlSplice. = $ PKey. '='. $ pValue .'&';
    }

    /* Concatenate the url of the array */
    /* If (false = empty ($ pValue) & (true = is_array ($ pValue ))){

    }*/
    }
    // Print_r ($ this-> m_PagingDataArray );
    }
    Return $ UrlSplice;
    }


    /*
    Returns the spliced html code (including js Code)
    */
    Public function GetPagingHtmlInfo ()
    {
    $ UrlSplice = $ this-> GetUrlSplice ();

    $ PageUrl = $ this-> m_Url. $ UrlSplice. 'page = ';
    $ PageUrls = $ PageUrl. ($ this-> m_Page-1 );
    $ PageUrly = $ PageUrl. ($ this-> m_Page + 1 );

    If ($ this-> m_PageCoent> 0 ){
    $ PageCoent = $ this-> GetPageCoent ($ PageUrl );
    } Else {
    $ PageCoent = null;
    }


    /* Define paging data */
    $ Html ='

      ';

      $ Home ='
    • Homepage
    • ';
      $ Previous ='
    • Previous Page
    • ';
      $ Next ='
    • Next Page
    • ';
      $ End ='
    • M_TotalFraction. '"> last page
    • ';

      $ HomeS ='
    • Homepage
    • ';
      $ Previuss ='
    • Previous Page
    • ';
      $ NextS ='
    • Next Page
    • ';
      $ EndS ='
    • Last page
    • ';


      /* When there is only one page of data, no url address is spliced */
      If ($ this-> m_TotalFraction = 1 ){
      $ Html. = $ HomeS. $ previuss. $ PageCoent. $ NextS. $ EndS;
      /* When no data exists, no url is spliced */
      } Elseif ($ this-> m_Page = $ this-> m_TotalFraction & $ this-> m_Total = 0 ){
      $ Html. = $ HomeS. $ previuss. $ PageCoent. $ NextS. $ EndS;
      /* When it is the first page */
      } Elseif ($ this-> m_Page = 1 ){
      $ Html. = $ HomeS. $ previuss. $ PageCoent. $ Next. $ End;

      /* At the end */
      } Elseif ($ this-> m_Page = $ this-> m_TotalFraction & $ this-> m_TotalFraction> 1 ){
      $ Html. = $ Home. $ Previous. $ PageCoent. $ NextS. $ EndS;

      /* Normal */
      } Else {
      $ Html. = $ Home. $ Previous. $ PageCoent. $ Next. $ End;
      }
      $ Html. ='
    • Current '. $ this-> m_Page.' page
    • Total '. $ this-> m_TotalFraction.' page
    • There are always '. $ this-> m_Total.' data records.

    ';

    /* Css Code */
    $ Css ='';

    Return $ Html. $ Css;
    }

    }
    // Usage
    /* Call the paging module */
    $ Configuration = array (
    'Total' => $ StudentCount, // total number of data records
    'Traction' => $ StudentPage, // number of entries displayed on each page
    'Pagecoent' => 3, // Number of pages displayed
    'Url' => './studentmanagement', // The url address of the page flip
    );
    // $ _ REQUEST: if the current query has other conditions, it will be automatically spliced.
    // $ Configuration: Configuration item
    $ PageingObj = new PagingModel ($ _ REQUEST, $ Configuration );
    $ This-> assign ('pageing', $ PageingObj-> GetPagingHtmlInfo ());

    AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

  • 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.