zoukankan      html  css  js  c++  java
  • 关于分页的类(有点粗糙)

    <?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;
        }
    }
    ?>

  • 相关阅读:
    python 端口扫描仪
    [ruby on rails] 深入(1) ROR的一次request的响应过程
    [ruby on rails] 跟我学之(10)数据输入验证
    [ruby on rails] 跟我学之(9)删除数据
    [ruby on rails] 跟我学之(8)修改数据
    [ruby on rails] 跟我学之(7)创建数据
    BZOJ 2301 [HAOI2011]Problem b (分块 + 莫比乌斯反演)
    BZOJ 2005 [Noi2010]能量采集 (数学+容斥 或 莫比乌斯反演)
    BZOJ 1497 [NOI2006]最大获利 (最小割)
    BZOJ [FJOI2007]轮状病毒 (找规律)
  • 原文地址:https://www.cnblogs.com/S-Ping/p/4093222.html
Copyright © 2011-2022 走看看