Home > Backend Development > PHP Tutorial > 求把版主这个分页类改成支持php4的

求把版主这个分页类改成支持php4的

WBOY
Release: 2016-06-23 14:05:36
Original
1294 people have browsed it

之前都是用版主的这个类来进行分页~~~但是最近有个服务器是php4版本~~查了一下资料~php4不支持public不支持static等一大堆~~~所以求高手指教~把下面这个分页类改成支持php4

ps:constant("page_size")是config文件中定义好的常量

<?phpclass 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 = '<a href=?reset>首页</a> <a href=?prve>上一页</a> <a href=?next>下一页</a> <a href=?end>尾页</a>';    $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."当前第".$page."页|共".$count."页";  }}/*把 $sql ="....."; $rs = mysql_query($sql); 或 $rs = mysql_query("select ....");之类的 改作 include 'paging.php'; $rs = paging::prepare($sql, 每页行数); 在需要出现分页条的地方写入 paging::bar(); 就可以了*/?>
Copy after login


回复讨论(解决方案)

php 4.3.4 通过
不知道你的版本,有问题再说

class paging {  //增加一个方法,用于在静态调用的方法间传递数据  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;	$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($count)= mysql_fetch_row($p);	paging::para('count', $count);	paging::para('size', $pagesize);	paging::para('page', $page);	return $rs;  }  function bar($tpl='') {	if(!$tpl) $tpl = '<a href=?reset>首页</a> <a href=?prve>上一页</a> <a href=?next>下一页</a> <a href=?end>尾页</a>';	$count = ceil(paging::para('count') / constant("page_size"));	$page = paging::para('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."当前第".$page."页|共".$count."页";  }}//php4 没有 http_build_query 函数,所以要自己定义一个if(! function_exists('http_build_query')):  function http_build_query($formdata, $numeric_prefix='', $mode=0) {        static $ar = array();        foreach($formdata as $k=>$v) {                if(is_array($v)) {                        if($mode++) http_build_query($v, $numeric_prefix.'['.$k.']');                        else http_build_query($v, $k);                }else {                        if($mode)                                $ar[] = $numeric_prefix.'['.$k.']='.urlencode($v);                        else                                $ar[] = (is_numeric($k) ? $numeric_prefix.$k : $k).'='.urlencode($v);                }        }        if(--$mode < 0) {                 $r = join('&',$ar);                 $ar = array();                return $r;        }        return '';  }endif;
Copy after login

php 4.3.4 通过
不知道你的版本,有问题再说PHP code?123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263class paging { //增加一个方法,用于在静态调用的方……

现在这台机子没有FTP所以回去之后再测试~~还有一个问题想问问就是用smarty做后台的时候,用到了frameset,结果页面显示空白,百度了解决方法之后已经检查了路径和编码(看的是这篇文章http://blog.csdn.net/wxlhlh001/article/details/7049938)。。。。。结果还是显示空白页面,单独显示是ok的,比如在地址栏输入header.php,menu.php,main.php都能正常显示.....

我不知道你遇到了什么问题,但我知道每一个框架页都有自己的处理程序

我不知道你遇到了什么问题,但我知道每一个框架页都有自己的处理程序

贴部分代码把~

根目录下有:
index.php
top.php
menu.php
main.php

根目录下有templates文件夹
templates文件夹下有:
index.html
top.html
menu.html
main.html

index.php

<?phpob_clean();require("login_check.php");require("../class/admin_class/smarty_class.php");$smarty->display("index.html");?>
Copy after login


top.php
<?phpob_clean();require("login_check.php");require("../class/admin_class/smarty_class.php");$session=new session();$name=$session->get_name();$smarty->assign("name",$name);$smarty->display("top.html");?>
Copy after login


menu.php
<?phpob_clean();require("login_check.php");require("../class/admin_class/smarty_class.php");$smarty->display("menu.html");?>
Copy after login


main.php
<?phpob_clean();require("login_check.php");require("../class/admin_class/smarty_class.php");$smarty->display("main.html");?>
Copy after login



index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>后台管理--红色理论研究社</title></head><frameset rows="80,*" cols="*" framespacing="1" frameborder="yes" border="1" bordercolor="#0000FF">  <frame src="top.php" name="topFrame" frameborder="yes" scrolling="No" noresize="noresize" bordercolor="#0000FF" id="topFrame" title="topFrame" />  <frameset rows="*" cols="96,*" framespacing="1" frameborder="yes" border="1" bordercolor="#0000FF">    <frame src="menu.php" name="leftFrame" frameborder="yes" scrolling="No" noresize="noresize" bordercolor="#0000FF" id="leftFrame" title="leftFrame" />    <frame src="main.php" name="mainFrame" frameborder="yes" bordercolor="#0000FF" id="mainFrame" title="mainFrame" />  </frameset></frameset><noframes><body></body></noframes></html>
Copy after login

http://localhost/admin/menu.php
http://localhost/admin/top.php

这些能正常显示

http://localhost/admin/index.php
页面显示空白

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template