Simple paging is a simple and easy-to-use paging class. You only need to add and modify one sentence in your original program. then you can post the code paging. php & lt ;? Phpclass & nbsp; Paging & nbsp; {& nbsp; public & nbsp; static & n simple Paging class
This is a simple and easy-to-use paging class. You only need to add or modify one sentence in your original program.
Post code first
Paging. php
Class Paging {
Public static $ count = 0;
Public static $ size = 0;
Public static $ page = 0;
Static function prepare ($ SQL, $ pagesize = 10 ){
$ Page = isset ($ _ GET ['Page'])? $ _ GET ['Page']: 1;
$ Pageon = ($ page-1) * $ pagesize;
$ SQL = preg_replace ('/select \ s/I', '$ 0SQL_CALC_FOUND_ROWS', $ SQL). "limit $ pageon, $ pagesize ";
$ Rs = mysql_query ($ SQL );
$ P = mysql_query ('select FOUND_ROWS ()');
List (self: $ count) = mysql_fetch_row ($ p );
Self: $ size = $ pagesize;
Self: $ page = $ page;
Return $ rs;
}
Static function bar ($ tpl = ''){
If (! $ Tpl) $ tpl = 'Last page of the previous homepage ';
$ Count = ceil (self: $ count/self: $ size );
$ Page = self: $ page;
Unset ($ _ GET ['Page']);
$ D = array (
'Reset' => 1,
'Prve' => $ page> 1? $ Page-1: 1,
'Next' => $ page <$ count? $ Page + 1: $ count,
'End' => $ count,
);
Foreach ($ d as $ k => $ v ){
$ _ GET ['Page'] = $ v;
$ Tpl = str_replace ($ k, http_build_query ($ _ GET), $ tpl );
}
Echo $ tpl;
}
}
You usually have statements like this.
$ SQL = ".....";
$ Rs = mysql_query ($ SQL );
Or
$ Rs = mysql_query ("select ....");
You only need to change
Include 'Paging. php ';
$ Rs = paging: prepare ($ SQL, number of lines per page );
Write to the place where paging entries need to appear
Paging: bar ();
It's easy!
------ Solution --------------------
Front-row worship mode.
This is the first time I have seen it.
$ SQL = preg_replace ('/select \ s/I', '$ 0SQL_CALC_FOUND_ROWS', $ SQL). "limit $ pageon, $ pagesize ";
SQL also uses preg_replace ......
------ Solution --------------------
Thanks for sharing. it is really convenient and easy to use. I learned.
------ Solution --------------------
Reference:
This is a simple and easy-to-use paging class. You only need to add or modify one sentence in your original program.
Post code first
Paging. php
PHP code
Class Paging {
Public static $ count = 0;
Public static $ size = 0;
Public static $ page = 0;
Static function prepare ($ SQL, $ ......