Please change the moderator this page class to support PHP4
Used to be the moderator of this class to be paged ~ ~ ~ ~ But recently there is a server is PHP4 version ~ ~ Check the data ~PHP4 does not support the public does not support static and so a large heap ~ ~ ~ so high finger teach ~ The following page class to support PHP4
Ps:constant ("Page_size") is a constant defined in the config file
Class Paging {
public static $count = 0;
public static $size = 0;
public static $page = 0;
static function Prepare ($sql, $pagesize = ")
{$pagesize =constant ("page_size");
$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 = 10;
Self:: $page = $page;
return $rs;
}
static function bar ($tpl = ") {
if (! $tpl) $tpl = ' First prev next last ';
$count = Ceil (self:: $count/constant ("page_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);
}
return $TPL. " Current section ". $page." Page | total ". $count." Page ";
}
}
/*
Put
$sql = "...";
$rs = mysql_query ($sql);
Or
$rs = mysql_query ("SELECT ...");
or something.
Change for
Include ' paging.php ';
$rs = paging::p repare ($sql, Number of rows per page);
Write to where the paging bar appears
Paging::bar ();
You can do it.
*/
?>
------Solution--------------------
PHP 4.3.4 through
I don't know your version, but I have a question.
Class Paging {
Add a method for passing data between methods that are statically invoked
function Para ($na) {
Static $ar;
if (Func_num_args () = = 1) return $ar [$na];
$ar [$na] = Func_get_arg (1);
}
function prepare ($sql, $pagesize = ") {
$pagesize =constant ("page_size");
$page = isset ($_get[' page ')? $_get[' page ': 1;
$pageon = ($page-1) * $pagesize;