Please change the page of the moderator to support PHP4

Source: Internet
Author: User
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;
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.