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');?> |