关于分页的类(有点粗糙)

<?php
class page
{
    public $tab;        //表名
    public $row;        //数据
    public $page;        //当前页
    public $totalpage;    //总页数
    public $totalsize;    //总条数
    public $pageindex;    //查找索引
    public $pagesize;    //每页显示条数
    public $lastpage;    //上一页
    public $nextpage;    //下一页
    function __construct($tab,$pagesize)
    {
        mysql_connect("127.0.0.1","root","123456");
        mysql_select_db("baonier");
        $this->tab=$tab;
        $this->pagesize=$pagesize;
        $sql="select * from ".$this->tab."";
        $query=mysql_query($sql);
        echo $this->totalsize=mysql_num_rows($query);
        $this->totalpage=ceil($this->totalsize/($this->pagesize-1));
        $this->page=isset($_GET['page'])?$_GET['page']:1;
                    
        $this->pageindex=($this->page-1)*$this->pagesize;
        $this->lastpage=$this->page-1;
        $this->nextpage=$this->page+1;
        
    }
    function get_array()
    {
        $sql="select * from ".$this->tab." limit ".$this->pageindex.",".$this->pagesize."";    
        $q=mysql_query($sql);
        $roww=array();
        while($rows=mysql_fetch_array($q))
        {
            $roww[]=$rows;
        }
        $this->row=$roww;
        return $this->row;
    }
    function get_page()
    {
        if($this->lastpage<1)
        {
            $this->lastpage=1;
        }
        if($this->nextpage>$this->totalpage)
        {
            $this->nextpage=$this->totalpage;
        }
        $div="<a href=\"?page=".$this->lastpage." \">上一页</a><a href=\"?page=".$this->nextpage."\">下一页</a>";
        return $div;
    }
}
?>

转载于:https://www.cnblogs.com/S-Ping/p/4093222.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值