This is a simple and easy to use paging class. Just add two sentences to your original program and change the sentence.
Post Code First
paging.php
-
-
PHP Code
-
<?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; The static function bar ($tpl = ') {if (! $tpl) $tpl = ' <a href=?reset> home </a> <a href=?prve> prev </A&G T
<a href=?next> Next page </a> <a href=?end> last </a> ';
$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;
}
}
Usually you have a statement like this $sql = "..."; $rs = mysql_query ($sql); or $rs = mysql_query ("SELECT ..."); You only need to change to include ' paging.php '; $rs = paging::p repare ($sql, Number of rows per page); Write Paging::bar () where the paging bar is required; It's OK, it's very simple!