简易分页类
这是一个简单易用的分页类。只需在你原有的程序中加两句、改一句就可以了
先贴代码
paging.php
<?php<br /> class Paging {<br /> public static $count = 0;<br /> public static $size = 0;<br /> public static $page = 0;<br /> static function prepare($sql, $pagesize=10) {<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;<br /> self::$page = $page;<br /> return $rs;<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 / self::$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 /> echo $tpl;<br /> }<br /> }<br />