一款由网页提供的php mysql 分页显示代码,样式比较多,php分页类的核心代码如下:
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- class Page{
-
- public $page_size="20";
- public $page_num;
- public $page_url="";
- public $pageval;
- public $page_ys;
- public $page_tf=false;
- public $page;
-
-
-
- function __construct($page_num,$page_size=""){
- $this->page_num=$page_num;
-
- if($page_size!=""){
- $this->page_size=$page_size;
- }
-
- $this->page_url=$_SERVER['SCRIPT_NAME'];
-
- if($this->page_num>$this->page_size){
- $this->page_ys=ceil($this->page_num/$this->page_size);
- $this->page_tf=true;
- }
-
- if(!emptyempty($_GET['page'])){
- if($_GET['page']>="1"){
- if($_GET['page']<=$this->page_ys){
- $this->pageval=$_GET['page'];
- }else{
- $this->pageval=$this->page_ys;
- }
- }else{
- $this->pageval="1";
- }
- }else{
- $this->pageval="1";
- }
-
- $this->page=($this->pageval-1)*$this->page_size;
-
- }
-
-
-
-
- function page_fy($val=""){
- if($this->page_tf==true){
- if($val==""){
- return $this->page_style_one();
- }else if ($val=="1"){
- return $this->page_style_two();
- }elseif ($val=="2"){
- return $this->page_style_three();
- }
- }
- }
-
-
-
- function page_style_one(){
- if($this->pageval=="1"){
- $up="1";
- }else{
- $up=$this->pageval-1;
- }
-
- if($this->pageval>=$this->page_ys){
- $down=$this->page_ys;
- }else{
- $down=$this->pageval+1;
- }
- $one="<a href='".$this->page_url."?page=1'>首页</a>";
- $two="<a href='".$this->page_url."?page=".$up."'>上一页</a>";
- $three="<a href='".$this->page_url."?page=".$down."'>下一页</a>";
- $four="<a href='".$this->page_url."?page=".$this->page_ys."'>末页</a>";
- return $page_echo = $one.$two.$three.$four;
- }
-
-
-
- function page_style_two(){
- $page_echo="";
- if($this->pageval=="1"){
- $up="1";
- }else{
- $up=$this->pageval-1;
- }
-
- if($this->pageval>=$this->page_ys){
- $down=$this->page_ys;
- }else{
- $down=$this->pageval+1;
- }
- $two="<a href='".$this->page_url."?page=".$up."'>上一页</a>";
- $three="<a href='".$this->page_url."?page=".$down."'>下一页</a>";
-
- if($this->page_ys>"6"){
-
- if($this->pageval<=3){
- $i=2;
- $i_to=5;
- }elseif ($this->pageval>=($this->page_ys-2)){
- $i=$this->page_ys-4;
- $i_to=$this->page_ys-1;
- }else{
- $i=$this->pageval-2;
- $i_to=$this->pageval+2;
- }
-
- if($this->pageval>4){
- $page_one="...";
- }else{
- $page_one="";
- }
-
- if($this->pageval<($this->page_ys-3)){
- $page_two="...";
- }else{
- $page_two="";
- }
-
- for ($i;$i<=$i_to;$i++){
- $page_echo.="<a href='".$this->page_url."?page=".$i."'>".$i."</a>";
- }
-
- }else{
- for ($i=2;$i<=($this->page_ys-1);$i++){
- $page_echo.="<a href='".$this->page_url."?page=".$i."'>".$i."</a>";
- }
-
- }
-
- return $two."<a href='".$this->page_url."?page=1'>1</a>".$page_one.$page_echo.$page_two."<a href='".$this->page_url."?page=".$this->page_ys."'>".$this->page_ys."</a>".$three;
-
- }
-
-
-
- function page_style_three(){
- return $this->page_style_two();
- }
- }
- ?>
PHP调用方法,代码如下:
- <style type="text/css">
-
- a{ color:#fff; text-decoration:none; padding:2px 5px; background-color:#09C; border:#F63 double 1px; margin:0 2px; font-size:14px;}
- a:hover{color:#f00; background-color:#CCC;}
- body{color:#999;}
- </style>
- <?php
-
- include 'p.php';
-
- $page=new Page('12345',"10");
-
-
- echo "样式二<br/>";
- echo "<br/>";
- echo "<br/>";
- echo $page->page_fy('1');
-
- echo "<br/>";echo "<br/>";echo "<br/>";echo "<br/>";
-
-
- echo "样式一<br/>";
- echo "<br/>";
- echo "<br/>";
- echo $page->page_fy();
-
-
- ?>
|