Heim > Backend-Entwicklung > PHP-Tutorial > php mysql分页实现代码_PHP教程

php mysql分页实现代码_PHP教程

WBOY
Freigeben: 2016-07-13 16:54:51
Original
875 Leute haben es durchsucht

这算是一款比较完美的分页类了,支持表单输入跳转,也支持select跳转分页,同时还支持上10页,下10页偏移分页哦。 */

这算是一款比较完美的分页类了,支持表单输入跳转,也支持select跳转分页,同时还支持上10页,下10页偏移分页哦。
*/

class wind_page 
{
    var $page;
      //现在所在页
    var $total;
      //记录总条数
    var $totalpage;
     //总页树
    var $pagesize;
      //每页显示条数
    var $offset;
      //偏移量
    var $result;
      //记录集合
    var $thispage;
      //记录总条数 //记录总条数 //记录总条数
    var $link;
      //连接(记录$_get变量)
    var $bar_mun;
      //bar显示的页数
    var $starttime;
      //开始时间
    var $bar_last;
      //导航条的持续页数
    var $bar_mid;
      //导航条中间页
    var $minpage;
      //导航条最小页
    var $maxpage;
      //导航条最大页
    var $key;
      //标识分页(一个页面多个分页时用与区分)
    var $style;
      //输出的风格
    var $pre_page_char;
      //上一页
    var $pre_page_image;
      //上一页图形
    var $pre_page_char_color;
      //上一页字体颜色
    var $next_page_char;
      //下一页
    var $next_page_image;
      //下一页图形
    var $next_page_char_color;
      //下一页字体颜色
    var $pre_groud_char;
      //上翻中间页数
    var $pre_groud_char_color;
      //上翻中间页数字体颜色
    var $next_groud_char;
      //下翻中间页数
    var $next_groud_char_color;
    //下翻中间页数字体颜色
    var $first_page_char;
    //首页
    var $first_page_char_color;
    //首页字体颜色
    var $last_page_char;
    //尾页
    var $last_page_char_color;
    //尾页字体颜色
    var $html_page_val;
    //html当前的页码值
    
    function wind_page($sql, $pagesize = 20, $bar_mun = 10, $style = 1,$this_page = 1,$html_page_val=1,$key = "") //构造函数()
    {
        $this->starttime = microtime();
        $this->pagesize = $pagesize;
          //每页显示条数
        $this->key = trim($key);
        $this->bar_mun = $bar_mun;
        $this->style = $style;
        $this->html_page_val = $html_page_val;
        //html当前的页码值
        $this->bar_last = $bar_mun-1;
        $this->bar_mid = floor($bar_mun/2);
        $this->sql = $sql;
        $result = mysql教程_query($this->sql);
        $this->total = mysql_num_rows($result);
        //记录总条数
        $this->totalpage = ceil($this->total/$this->pagesize);
        //总页数
        //$this->page = ceil($_get[$this->key."page"]);
        $this->page = $this_page;
        //现在所在页
        if ($this->page == "" || $this->page page))$this->page = 1;
        $this->page = min($this->page, $this->totalpage);
        $this->thispage = $this->pagesize;
        if ($this->page * $this->pagesize > $this->total) {
            $this->thispage = $this->total-($this->page-1) * $this->pagesize;
        };
        $this->sql .= " limit ".($this->pagesize * ($this->page-1)).", ".$this->pagesize;
          //开始读取的条数
       //echo "
";
        $this->result = mysql_query($this->sql);
        $this->getvar();
       
        $this->pre_page_char = "上一页";
        $this->pre_page_image = "php mysql分页实现代码_PHP教程";
        $this->next_page_char = "下一页";
        $this->next_page_image = "php mysql分页实现代码_PHP教程";
        $this->pre_groud_char = "上一组";
        $this->next_groud_char = "下一组";

    }
   
    function getvar() //取得除page外的其他get变量
    {
        $this->link = "";
        foreach($_get as $key => $vaule) {
            if (strtolower($key)  !== $this->key."page") $this->link  .= "&$key=$vaule";
        }
    }
    
    function pre_page($color="#909090",$sign=0) //上一页
    {
        if ($this->page > 1) { 
            return "page-1).".html" class="ab">pre_page_char_color."">".$this->pre_page_char."";
        } else
        {
           return "".$this->pre_page_char."";
        }
      
    }
    
    function next_page($color="#909090",$sign=0) //下一页
    {
        if ($this->page totalpage) {
          
              return "page+1).".html" class="ab">".$this->next_page_char."";
           
        } else {
          
             return "".$this->next_page_char."";
        }
    }
    
    function pre_groud($char = "     {
        if ($this->page bar_mid+1)) {
            return "".$this->pre_groud_char."";
            //return $this->pre_groud_char;
        } else {
            $pre_gpage = ($this->page-$this->bar_mid             $this->page-$this->bar_mid;
            return "".$this->pre_groud_char."";
        }
    }
    
    function next_groud($char = ">>", $color = "#909090") //下一组
    {
        if (($this->totalpage-$this->page) bar_mid-1)) {
            return "".$this->next_groud_char."";
        } else {
            $next_gpage = ($this->page+$this->bar_mid totalpage)?$this->page+$this->bar_mid:
            $this->totalpage;
            return "".$this->next_groud_char."";
        }
    }
    
    function mun($lcolor = "#ff6633", $acolor = "#ff6633", $left = " ", $right = " ") //数字导航栏
    {
        $link = "";
        $this->minpage = ($this->page-$this->bar_mid page-$this->bar_mid);
        $this->maxpage = $this->minpage+$this->bar_last;
        if ($this->maxpage > $this->totalpage) {
            $this->maxpage = $this->totalpage;
            $this->minpage = ($this->maxpage-$this->bar_last maxpage-$this->bar_last;
        }
       for($i = $this->minpage; $i maxpage; $i++)
        {
         /* 循环输出页码 */
            $i = sprintf("%02d",$i);
            //不足两位的前面补0
            $char = $left.$i.$right;
            //导航条左右两边加窄
            if ($i == $this->page)
            {
             /* 假如是当前页则不加链接 */
                $link.= "".$char."";
            }
            else
             {
                //$link  .= "key."page=".$i.$this->link."" >".$char."";
                $link.= "".$char."";
                //关键把$link 加在新资料加入之后
            }
        }
        echo "
";
        return $link;
    }
    
    
    function jump_bar($class = "jump_bar") //下拉跳转
    {
        $link = "";
        return $link;
    }
    
    function mun_bar() //整条数字导航栏  [][>>]
    {
        //return $this->first_groud().$this->pre_groud().$this->pre_page().$this->mun().$this->next_page().$this->next_groud().$this->last_groud();
        return $this->pre_groud()." ".$this->pre_page().$this->mun().$this->next_page()." ".$this->next_groud();
    }
    function page_button()
    { //整条数字导航栏  []
        //return $this->first_groud().$this->pre_groud().$this->pre_page().$this->mun().$this->next_page().$this->next_groud().$this->last_groud();
        return $this->pre_page('#909090',1).$this->mun().$this->next_page('#909090',1);
    }
    
    function total_bar($coloro = "#000000", $colorn = "red") //统计数字  页次:1/4310 每页:20 共计:4310页 本页:20
    {
        return "页次:$this->page/$this->totalpage 每页:$this->pagesize 共计:$this->totalpage页  本页:$this->thispage";
    }
    
    // 整条导航栏
    //页次:1/4310 每页:20 共计:4310页 本页:20 [][>>]
    function page_bar($coloro = "#000000", $colorn = "red") {
        return "


           
           
           
           
           
           
           
           
".$this->total_bar()." ".$this->mun_bar()." ".$this->jump_bar()."
".$this->mm_jumpmenu();
    }
    
    function taketime($color = "#000000") //计算执行时间
    {
        return "
本页执行时间".abs((microtime()-$this->starttime) * 1000)."毫秒
";
    }
    
    function style() //输出分页的样式
    {
        $style_num = $this->style;
        
        if ($this->totalpage  != 0) //如果总页数=0 ,表示无分页
        {
            switch($style_num) {
                case 1:
                return $this->page_bar();
                //页次:1/4310 每页:20 共计:4310页 本页:20 [][>>]
                break;
                case 2:
                echo $this->mun_bar();
                //整条数字导航栏  [][>>]
                break;
                case 3:
                echo $this->page_button();
                //整条数字导航栏  []
                break;
            }
        }
    }
    
    function mm_jumpmenu() //网页特效的跳转
    {
        //window.open(selobj.options[selobj.selectedindex].value,targ);
        return "";
    }
    
    function first_groud($char = "          if ($this->page == 1) {
            return "".$char."";
        } else {
            //$pre_gpage=($this->page-$this->bar_midpage-$this->bar_mid;
            $pre_gpage = 1;
            return "key."page=".$pre_gpage.$this->link."" title="上一组">".$char."";
        }
    }
    
    function last_groud($char = " >>", $color = "#000000") {
        if ($this->page == $this->totalpage) {
            return "".$char."";
        } else {
            //$pre_gpage=($this->page-$this->bar_midpage-$this->bar_mid;
            $pre_gpage = $this->totalpage;
            return "key."page=".$pre_gpage.$this->link."" title="上一组">".$char."";
        }
    }
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/631723.htmlTechArticle这算是一款比较完美的分页类了,支持表单输入跳转,也支持select跳转分页,同时还支持上10页,下10页偏移分页哦。*/ 这算是一款比较完美...
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage