php mysql paging implementation code_PHP tutorial

WBOY
Release: 2016-07-13 16:54:51
Original
861 people have browsed it

This is a relatively perfect paging class. It supports form input jump and select jump paging. It also supports offset paging for the previous 10 pages and the next 10 pages. */

This is a relatively perfect paging class. It supports form input jump and select jump paging. It also supports offset paging for the previous 10 pages and the next 10 pages.
*/

class wind_page
{
var $page;
//The current page
var $total;
//Total number of records
var $totalpage;
//Total page tree
var $pagesize;
//Number of items displayed on each page
var $offset;
//Offset
var $result;
//Record collection
var $thispage;
//Total number of records //Total number of records //Total number of records
var $link;
//Connect (record $_get variable)
var $bar_mun;
//Number of pages displayed by bar
var $starttime;
//Start time
var $bar_last;
//The number of continuous pages of the navigation bar
var $bar_mid;
//Navigation bar middle page
var $minpage;
//Navigation bar minimum page
var $maxpage;
//Maximum page of navigation bar
var $key;
//Identify pagination (used to distinguish multiple paginations on one page)
var $style;
//Output style
var $pre_page_char;
//Previous page
var $pre_page_image;
//Previous page graphics
var $pre_page_char_color;
//Font color of previous page
var $next_page_char;
//Next page
var $next_page_image;
//Next page graphics
var $next_page_char_color;
//Next page font color
var $pre_groud_char;
//Turn up the middle page
var $pre_groud_char_color;
//Number font color of the middle page when turning up
var $next_groud_char;
//Turn down the middle page
var $next_groud_char_color;
//Number font color when turning down the middle page
var $first_page_char;
//Home
var $first_page_char_color;
//Home page font color
var $last_page_char;
//Last page
var $last_page_char_color;
//Last page font color
var $html_page_val;
//html current page number value
​  
Function wind_page($sql, $pagesize = 20, $bar_mun = 10, $style = 1,$this_page = 1,$html_page_val=1,$key = "") //Constructor ()
{
           $this->starttime = microtime();
$this->pagesize = $pagesize;
//Number of items displayed on each page
            $this->key = trim($key);
            $this->bar_mun = $bar_mun;
$this->style = $style;
           $this->html_page_val = $html_page_val;
//html current page number value
$this->bar_last = $bar_mun-1;
           $this->bar_mid = floor($bar_mun/2);
           $this->sql = $sql;
           $result = mysql tutorial_query($this->sql);
           $this->total = mysql_num_rows($result);
//Total number of records
$this->totalpage = ceil($this->total/$this->pagesize);
//Total number of pages
//$this->page = ceil($_get[$this->key."page"]);
           $this->page = $this_page;
        //现在所在页
        if ($this->page == "" || $this->page < 1 || !is_numeric($this->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 = "";
        $this->next_page_char = "下一页";
        $this->next_page_image = "";
        $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 < $this->totalpage) {
          
              return "page+1).".html" class="ab">".$this->next_page_char."";
           
        } else {
          
             return "".$this->next_page_char."";
        }
    }
    
    function pre_groud($char = "<<", $color = "#909090") //上一组
    {
        if ($this->page <= ($this->bar_mid+1)) {
            return "".$this->pre_groud_char."";
            //return $this->pre_groud_char;
        } else {
            $pre_gpage = ($this->page-$this->bar_mid < 0)?1:
            $this->page-$this->bar_mid;
            return "".$this->pre_groud_char."";
        }
    }
    
    function next_groud($char = ">>", $color = "#909090") //下一组
    {
        if (($this->totalpage-$this->page) <= ($this->bar_mid-1)) {
            return "".$this->next_groud_char."";
        } else {
            $next_gpage = ($this->page+$this->bar_mid < $this->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 < 1) ? 1:($this->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 < 1) ? 1: $this->maxpage-$this->bar_last;
        }
       for($i = $this->minpage; $i <= $this->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() //整条数字导航栏  [<<][<][01][02][03][04][05][06][07][08][09][10][>][>>]
    {
        //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()
    { //整条数字导航栏  [<][01][02][03][04][05][06][07][08][09][10][>]
        //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 [<<][<][01][02][03][04][05][06][07][08][09][10][>][>>]
    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() //Output paging style
{
$style_num = $this->style;
                                   
If ($this->totalpage != 0) //If the total number of pages = 0, it means no paging
           {
                switch($style_num) {
               case 1:
                    return $this->page_bar();
//Page: 1/4310 Each page: 20 Total: 4310 pages This page: 20 [<<][<][01][02][03][04][05][06][07 ][08][09][10][>][>>]
                 break;
                case 2:
echo $this->mun_bar();
//The entire digital navigation bar [<<][<][01][02][03][04][05][06][07][08][09][10][> ][>>]
                 break;
                case 3:
echo $this->page_button();
//The entire digital navigation bar [<][01][02][03][04][05][06][07][08][09][10][>]
                 break;
            }
}
}
​  
Function mm_jumpmenu() //Jump of web page special effects
{
​​​​ //window.open(selobj.options[selobj.selectedindex].value,targ);
          return "
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!