Php paging class (source code + instance)

Source: Internet
Author: User
Php paging class (source code + instance)
Share a php paging class, which is well written. we provide two calling instances for this paging class for your reference.

1. php paging code

     Number = $ number; $ this-> N_p_p = $ n_p_p; $ this-> Pages = ceil ($ this-> Number/$ this-> N_p_p ); $ this-> Buttons = $ buttons; $ page_number = ($ page_number> $ this-> Pages )? $ This-> Pages: $ page_number; $ this-> Page_number = $ page_number; $ this-> Ret ();} public function Show_Pagination ($ link, $ get = 'page', $ p_class_name = 'pagination') {// if pages = 1, no need to print pagination if ($ this-> Pages = 1) return; // $ link is the addres of current page // $ get is name of get method // echo pagination's p echo'

'; // Echo pre button if ($ this-> Page_number> 1) echo 'page _ number-1 ). '"> Per'; else echo 'per '; // print button $ this-> Buttons = (int) $ this-> Buttons; $ start_counter = $ this-> Page_number-floor ($ this-> Buttons/2 ); // for normal mode $ end_conter = $ this-> Page_number + floor ($ this-> Buttons/2 ); // for normal mode // try to buttons exactly equal to $ Buttons if ($ start_counter <1) $ end_conter = $ end_conter + abs ($ start_counter ); if ($ end_conter> $ this-> Pages) $ start_counter = $ start_counter-($ end_conter-$ this-> Pages ); if ($ this-> Page_number-floor ($ this-> Buttons/2) <1) $ end_conter ++; for ($ I = $ start_counter; $ I <= $ end_conter; $ I ++) {if ($ I> $ this-> Pages | $ I <1) continue; // no print less than 1 value or grater than totall page if ($ I ==$ this-> Page_number) echo ''. $ I. ''; // change current page 'class else echo ''. $ I. ''; // normal pages} // echo next button if ($ this-> Page_number <$ this-> Pages) echo 'page _ number + 1 ). '"> nex'; else echo 'nex'; // close p tag echo'

';} // Give the page number and return start and end of selection private function Ret () {$ this-> Start = ($ this-> Page_number-1) * $ this-> N_p_p); $ this-> End = $ this-> N_p_p ;}}

2. example 1 of the paging class

   Php paging class example ---bbs.it-home.org  
     Start, $ pagination-> End "); // echo your result while ($ row = mysql_fetch_assoc ($ SecondQuery) {echo 'Id = '. $ row ['id'].'
';} // Show pagination: $ pagination-> Show_Pagination ("ExampleMysql. php? Param1 = value1 ", 'page', 'pagination');?>

3. paging call Example 2

   Php paging Class Call example -bbs.it-home.org  
     Start, $ cat-> End // for show: $ cat-> Show_Pagination ("example. php? ", 'Pagination', 'pagination');?>

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.