Home Backend Development PHP Tutorial 急好看实用的PHP+JS分页!效果类似百度

急好看实用的PHP+JS分页!效果类似百度

Jun 13, 2016 am 10:52 AM
amp limit quot start

急!求一个好看实用的PHP+JS分页!效果类似百度
急!求一个好看实用的PHP+JS分页!效果类似百度!

  效果如下:

1 2 3 4 5 6 7 8 9 10 下一页 共有?页

当不是第一页的时候,显示如下:

上一页 1 2 3 4 5 6 7 8 9 10 下一页 共有 ?页

其中,用“另一种颜色标记出当前显示的是哪一页”

该分页代码能跟MYSQL数据库连接使用,实现像百度的分页效果!

  小弟是新手,都吧知道如何下手,请各位大哥帮帮忙!谢谢!

------解决方案--------------------

PHP code
function _setPage($baseUrl, $total, $start, $limit, $parm=""){  if($total != 0) $pages = $total/$limit;  else $pages = 0;   if(empty($start)) $start=0;   if(empty($limit)) $limit=20;      if($start>$total)$start=$total-$limit;   if($start100) $limit=100;      //$start = $start - $top;   $showpage = 10;   $currentpage=$start/$limit;   if($currentpage $total/$limit ){        $pageno=$currentpage -5;     }else{        $pageno=$currentpage - 5;     }     $i=$pageno*$limit;   }   if($total==0) $currentpage = -1;   $strPage =  "总[" . ($currentpage + 1) . "/" . ceil($pages) . "]页  ";   $page=0;   $strPage .= "";   if($start/$limit > $showpage)   {        $tmp = ($pageno - 1)* $limit;        $strPage.= "<a href="%24baseUrl&%24parm&start=%22.(%24tmp).%22&limit=%24limit">";   }      while($i ". ($pageno + 1) ." ";      }      else      {        $strPage .= "</a><a href="%24baseUrl&%24parm&start=%22.(%24pageno*%24limit).%22&limit=%24limit">".($pageno + 1)."</a> ";      }      $pageno++;      $page++;      $i+=$limit;      if($page > $showpage)      {        $strPage.= "<a href="%24baseUrl&%24parm&start=%22.(%24pageno*%24limit).%22&limit=%24limit">>></a>";        break;      }    }        if($start>0){        $strPage .= " <a href="%24baseUrl?%24parm&start=0&limit=%24limit">首页</a> ";    }else{        $strPage .= " 首页 ";    }    if($start>0){        $strPage .=  " <a href="%24baseUrl&%24parm&start=%22.(%24start-%24limit).%22&limit=%24limit">上一页</a> ";    }    if($start+$limit下一页 ";    }    if($start+$limit尾页 ";    }else{      $strPage .= " 尾页 ";    }    return $strPage;}<br><font color="#e78608">------解决方案--------------------</font><br>为什么要JS的?<br><font color="#e78608">------解决方案--------------------</font><br>$baseUrl为页面基本的url,比如说index.php?m=table&a=list<br>$total为你要分页的记录的总数,用来计算有多少页的.<br>$start为当前页开始的记录条数.<br>$limit为每页显示的条数,这个可以定为常量.<br>$parm为额外的参数,比如说你在$baseUrl的基础上又添加了一个search='news'的话,可以在这里添加,以便追加到url里.<br><font color="#e78608">------解决方案--------------------</font><br>学习。<div class="clear">
                 
              
              
        
            </div>
Copy after login
Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if docker start cannot start? What should I do if docker start cannot start? Oct 21, 2022 pm 03:43 PM

Solution to docker start failure: 1. Check the running status, and then release the occupied memory through the "echo 3 &gt; /proc/sys/vm/drop_caches" command; 2. Use "$netstat -nltp|grep .. ." command to check whether the port has been occupied. If it is found to be occupied after going online, change it to an available port and restart.

Detailed explanation of how to use take and limit in Laravel Detailed explanation of how to use take and limit in Laravel Mar 10, 2024 pm 05:51 PM

"Detailed explanation of how to use take and limit in Laravel" In Laravel, take and limit are two commonly used methods, used to limit the number of records returned in database queries. Although their functions are similar, there are some subtle differences in specific usage scenarios. This article will analyze the usage of these two methods in detail and provide specific code examples. 1. Take method In Laravel, the take method is used to limit the number of records returned, usually combined with the orderBy method.

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

What coin is AMP? What coin is AMP? Feb 24, 2024 pm 09:16 PM

What is AMP Coin? The AMP token was created by the Synereo team in 2015 as the main trading currency of the Synereo platform. AMP token aims to provide users with a better digital economic experience through multiple functions and uses. Purpose of AMP Token The AMP Token has multiple roles and functions in the Synereo platform. First, as part of the platform’s cryptocurrency reward system, users are able to earn AMP rewards by sharing and promoting content, a mechanism that encourages users to participate more actively in the platform’s activities. AMP tokens can also be used to promote and distribute content on the Synereo platform. Users can increase the visibility of their content on the platform by using AMP tokens to attract more viewers to view and share

Comparison of functions and usage of take and limit in Laravel Comparison of functions and usage of take and limit in Laravel Mar 09, 2024 pm 09:09 PM

Take and limit are two commonly used methods in Laravel to limit the number of query result sets. Although they have certain similarities in functionality, they differ in usage and some details. This article will conduct a detailed comparison of the functions and usage of the two methods, and provide specific code examples to help readers better understand the differences between them and how to apply them correctly. 1.take method The take method is in the LaravelEloquent query builder

What to do if node start reports an error What to do if node start reports an error Dec 29, 2022 pm 01:55 PM

Solution to node start error: 1. Execute "node xx.js" directly in the terminal; 2. Add start startup item "scripts": {"test": "echo \"Error: no test specified\" && exit 1 ","start":"node service.js"}"; 3. Re-execute "npm start".

How to use the limit and skip functions of Stream in Java for stream operations How to use the limit and skip functions of Stream in Java for stream operations Jun 26, 2023 pm 03:55 PM

StreamAPI was introduced in Java 8, which can greatly simplify the operation of collections. The Stream class provides many functional methods for operating on streams, including filtering, mapping, merging, and more. Among them, limit and skip are two functions used to limit the number of elements in stream operations. 1. Limit function The limit function is used to limit the number of elements in the stream. It accepts a long type parameter n, which represents the number of limits. After calling the limit function, a new stream is returned, which only contains

How to use the start method and run method in Java thread How to use the start method and run method in Java thread Apr 20, 2023 am 08:58 AM

start method and run method The $start()$ method is used to start a thread. At this time, the thread is in the ready (runnable) state and is not running. Once the $cpu$ time slice is obtained, the $run()$ method starts to be executed. . Directly calling the $run()$ method only calls a method in a class, which is essentially executed in the current thread. Therefore, it can only be achieved by using the $start()$ method to call the $run()$ method. True multithreading. Sample code@Slf4j(topic="c.Test4")publicclassTest4{publicstaticvoidmain(Strin

See all articles