Heim >Backend-Entwicklung >PHP-Tutorial > 求把版主这个分页种改成支持php4的
求把版主这个分页类改成支持php4的
之前都是用版主的这个类来进行分页~~~但是最近有个服务器是php4版本~~查了一下资料~php4不支持public不支持static等一大堆~~~所以求高手指教~把下面这个分页类改成支持php4
ps:constant("page_size")是config文件中定义好的常量
<?php<br /> class paging {<br /> public static $count = 0;<br /> public static $size = 0;<br /> public static $page = 0;<br /> <br /> <br /> static function prepare($sql, $pagesize='') <br /> { $pagesize=constant("page_size");<br /> $page = isset($_GET['page']) ? $_GET['page'] : 1;<br /> $pageon = ($page - 1) * $pagesize;<br /> $sql = preg_replace('/select\s/i', '$0SQL_CALC_FOUND_ROWS ', $sql) . " limit $pageon, $pagesize";<br /> $rs = mysql_query($sql);<br /> $p = mysql_query('SELECT FOUND_ROWS()');<br /> list(self::$count)= mysql_fetch_row($p);<br /> self::$size= $pagesize=10;<br /> self::$page = $page;<br /> return $rs;<br /> }<br /> <br /> <br /> <br /> static function bar($tpl='') {<br /> if(!$tpl) $tpl = '<a href=?reset>首页</a> <a href=?prve>上一页</a> <a href=?next>下一页</a> <a href=?end>尾页</a>';<br /> $count = ceil(self::$count / constant("page_size"));<br /> $page = self::$page;<br /> unset($_GET['page']);<br /> $d = array(<br /> 'reset' => 1,<br /> 'prve' => $page > 1 ? $page - 1 : 1,<br /> 'next' => $page < $count ? $page + 1 : $count,<br /> 'end' => $count,<br /> );<br /> foreach($d as $k=>$v) {<br /> $_GET['page'] = $v;<br /> $tpl = str_replace($k, http_build_query($_GET), $tpl);<br /> }<br /> return $tpl."当前第".$page."页|共".$count."页";<br /> }<br /> }<br /> /*<br /> <br /> 把<br /> $sql =".....";<br /> $rs = mysql_query($sql);<br /> 或<br /> $rs = mysql_query("select ....");<br /> 之类的 <br /> 改作<br /> include 'paging.php';<br /> $rs = paging::prepare($sql, 每页行数);<br /> 在需要出现分页条的地方写入<br /> paging::bar();<br /> <br /> 就可以了<br /> <br /> <br /> */<br /> ?>
class paging {<br> //增加一个方法,用于在静态调用的方法间传递数据<br> function para($na) {<br> static $ar;<br> if(func_num_args() == 1) return $ar[$na];<br> $ar[$na] = func_get_arg(1);<br> }<br> function prepare($sql, $pagesize='') {<br> $pagesize=constant("page_size");<br> $page = isset($_GET['page']) ? $_GET['page'] : 1;<br> $pageon = ($page - 1) * $pagesize;<br> $sql = preg_replace('/select\s/i', '$0SQL_CALC_FOUND_ROWS ', $sql) . " limit $pageon, $pagesize"; <div class="clear"> </div>