最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php分页类
时间:2008-04-17 编辑:简简单单 来源:一聚教程网
class conn{
function __construct(){
require("config.php");
$conn = @mysql_connect($host,$root,$pass);
@mysql_select_db($db);
if(!$conn){
echo "无法连接".mysql_errno() . ":" . mysql_error() ;
exit;
}
}
function query($sql){
$result = @mysql_query($sql);
if (!$result) {
echo mysql_errno().":".mysql_error();
exit;
}
return $result;
}
function next($result){
return @mysql_fetch_array($result);
}
function count_row($result){
$row = @mysql_num_rows($result);
return $row;
}
function close($result){
@mysql_free_result($result);
@mysql_close();
}
}
class fenye extends conn{
public $sql;
public $page;
public $countpage;
public $pagesize;
public $result;
function __construct($sql,$page,$pagesize){
$this->sql = $sql;
$this->page = $page;
$this->countpage = $countpage;
$this->pagesize = $pagesize;
parent::__construct();
$result = parent::query($sql);
$num = parent::count_row($result);
$this->countpage = ceil($num/$pagesize);
$a = ($page-1)*$pagesize;
$limit = "limit $a,$pagesize";
$this->sql = $sql.$limit;
$this->result = parent::query($this->sql);
}
function getlimit(){
return $this->sql;
}
function next(){
return parent::next($this->result);
}
function foor(){
$a = $this->page -1;
$b = $this->page +1;
if ($this->page == 1) {
echo "首页"." ";
}else echo "首页"." ";
if($this->page >1)
echo "上页"." ";
else echo "上页 ";
for ($i =1;$i <= $this->countpage;$i++){
echo "$i"." ";
}
if($this->page < $this->countpage)
echo "下页"." ";
else echo "下页 ";
if ($this->page == $this->countpage) {
echo "末页"." ";
}else echo "末页";
#######################
}
}
####################
if (isset($_GET['page'])) {
$page = $_GET['page'];
}else $page = 1;
$sql = "select * from guestbook ";
$pagesize =3;
$p = new fenye($sql,$page,$pagesize);
$sql = $p->getlimit();
$result = $p->query($sql);
while($row = $p->next()){
echo $row['id']."
";
}
$p->foor();
$p->close($result);
?>
相关文章
- php分页可利用表格来分页类 12-09
- 两款超php分页类代码 01-26
- 又一款php分页类代码 08-30
- PHP分页类 03-13
- 不错的PHP分页类 03-10
- PHP导出数据超时的优化建议解读 10-31