Share my first PHP + MySQL pagination class

xiaoxiao2021-03-06  62

I have seen a few paging classes before, it is relatively complicated, and I can't understand those code, and I found that when I want to query the data in a composite condition, it is very difficult. So I want to write one yourself. For five months of using PHP, I just seem to understand for the concept and use of the class. This is the first time I wrote the class - page navigation class, I hope to have a new hand, there is also a phper like me! ! / * _________________________________ CLASS NAME: SHOWPAGE _________________________________ Copyright (c): ERLDY (scarecrow) Author: Arvan [E-mail: erldy@126.com QQ: 103808353] Create date: 2004-09-27 ________________________________ * / / ***** Example: $ SQL = "Select Count (*) As Count from $ TBL"; $ DB-> Query; $ db-> next_record (); $ count = $ db-> f (count); // Total number $ page = new showpage; $ page-> Total = $ count; $ page-> linkary = array (); // use array ("ID" => $ ID) this Array deliver URL variable $ sql = "Select * from $ TBL Order by Sortid Desc Limit". $ Page-> offset (); $ db-> query ($ sql); $ showpage = $ page-> showlink ();

***** / Class showpage {var $ pagePage; / / The number of records in each page is Var $ TOTAL; // Record Total VAR $ linkary; // URL parameter array, for composite condition query paging display conditions Very easy to use / / Get the total number of pages function pageCount ($ TOTALPAGE = ($ this-> Total% $ this-> pagesize == 0)? Floor ($ this-> Total / $ this-> Pagesize): Flor ($ this- > Total / $ this-> Pagesize 1; Return $ TOTALPAGE;} // Get the current page Function Pagenum () {$ Page = ($ _GET ['Page'])! = ""? $ _Get [ 'Page']: $ page;} // query statement positioning pointer function offset () {= ($ this-> Pagenum ()> $ this-> pagecount ()) {// $ this- > Pagenum = $ THIS-> PageCount (); $ Pagemin = max (0, $ this-> Total - $ this-> PageSize - 1);} else f ($ this-> Pagenum () == 1) {$ Pagemin = 0;} else {$ Pagemin = min ($ this-> Total - 1, $ this-> PageSize * ($ this-> Pagenum () - 1));} Return $ PAGEMIN. ",". -> Pagesize;} // positioning home Function FRISTPAGE () {$ frist = ($ this-> Pagenum () <= 1)? "Home": " URL ($ this-> linkary). "/"> Home "; Return $ Frist; } // Positioned Previous Function Prepage () {$ prepage = $ this-> Pagenum () - 1; $ previous = ($ this-> Pagenum ()> = 2)? " Previous ": "Previous"; Return $ Previous;} // Position Next Function NextPage () {$ nextpage = $ this-> Pagenum () 1; $ Next = ($ this-> Pagenum () - 1)? "

Next page ":" Next "; Return $ next;} // Positioning Function LastPage () {$ last = ($ this-> Pagenum ()> = $ @> PageCount )))? "Last": " URL ($ this-> linkary)." / "> Last" "; RETURN $ Last;} // Down-down Jump Page Function Jumppage () {$ Jump =" The current No. B> ". $ This-> Pagenum ()." page A total of ". $ this-> pagecount (). " page jump to