search
HomeBackend DevelopmentPHP Tutorialphp mysql paging implementation code_PHP tutorial

php mysql paging implementation code_PHP tutorial

Jul 13, 2016 pm 04:54 PM
mysqlphpcodePaginationaccomplishsupportpaymentComparekindbeautifulformJumpenter

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 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 paging implementation code_PHP tutorial";
        $this->next_page_char = "下一页";
        $this->next_page_image = "php mysql paging implementation code_PHP tutorial";
        $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() //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 [][>>]
                 break;
                case 2:
echo $this->mun_bar();
//The entire digital navigation bar [ ][>>]
                 break;
                case 3:
echo $this->page_button();
//The entire digital navigation bar []
                 break;
            }
}
}
​  
Function mm_jumpmenu() //Jump of web page special effects
{
​​​​ //window.open(selobj.options[selobj.selectedindex].value,targ);
          return "

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631723.htmlTechArticleThis is a relatively perfect paging class. It supports form input jumps and select jump paging. It also supports offset pagination for the previous 10 pages and the next 10 pages. */ This is a perfect one...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

What is the importance of setting the httponly flag for session cookies?What is the importance of setting the httponly flag for session cookies?May 03, 2025 am 12:10 AM

Setting the httponly flag is crucial for session cookies because it can effectively prevent XSS attacks and protect user session information. Specifically, 1) the httponly flag prevents JavaScript from accessing cookies, 2) the flag can be set through setcookies and make_response in PHP and Flask, 3) Although it cannot be prevented from all attacks, it should be part of the overall security policy.

What problem do PHP sessions solve in web development?What problem do PHP sessions solve in web development?May 03, 2025 am 12:02 AM

PHPsessionssolvetheproblemofmaintainingstateacrossmultipleHTTPrequestsbystoringdataontheserverandassociatingitwithauniquesessionID.1)Theystoredataserver-side,typicallyinfilesordatabases,anduseasessionIDstoredinacookietoretrievedata.2)Sessionsenhances

What data can be stored in a PHP session?What data can be stored in a PHP session?May 02, 2025 am 12:17 AM

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

How do you start a PHP session?How do you start a PHP session?May 02, 2025 am 12:16 AM

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

What is session regeneration, and how does it improve security?What is session regeneration, and how does it improve security?May 02, 2025 am 12:15 AM

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use