首页 >php教程 >PHP源码 >PHP分页 upgrade 20130125

PHP分页 upgrade 20130125

PHP中文网
PHP中文网原创
2016-05-25 17:12:531900浏览

PHP分页 upgrade 20130125

分页用Class 这也太浪费资源了吧
@ 20130125
multi($total,  $limit,  $displayTab,  $uri = NULL);
@parameter
$total             记录总数
$limit              单页记录数
$displayTab    定位按钮个数

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8" /> 
<title>multi</title> 
<style> 
a, input, select, textarea { outline: medium none; } 
a:hover { background-color: #E5EDF2; } 
.current { background-color: #E5EDF2; 
border: 1px solid #C2D5E3; 
color: #000000; display: block; float: left; font-family: Tahoma; 
font-size: 13px; font-weight: bold; line-height: 26px; margin-left: 5px; padding: 0 10px; 
text-align: center; text-decoration: none; } 
.common { border: 1px solid #C2D5E3; color: #000000; display: block; float: left; 
font-family: Tahoma; font-size: 13px; line-height: 26px; margin-left: 5px; padding: 0 10px; 
text-align: center; text-decoration: none; } 
.jump { border: 1px solid #C2D5E3; color: #000000; display: block; float: left;
 font-family: Tahoma; font-size: 13px; line-height: 26px; margin-left: 5px; padding: 0 10px;
  text-align: center; text-decoration: none; } 
</style> 
</head> 
  
<body> 
<?php 
 echo multi(1000, 10, 10); 
 function multi($total, $limit, $displayTab, $uri = NULL) { 
    if($total <= $limit || $total == $limit) return (bool)false; 
    $retval = &#39;&#39;; 
    $maxRange = $range = ceil($total/$limit); 
    $displayTab = $maxRange < $displayTab ? $maxRange : $displayTab; 
    $page = !empty($_GET[&#39;page&#39;]) && is_numeric($_GET[&#39;page&#39;]) ?  
    (intval($_GET[&#39;page&#39;]) > 0 && intval($_GET[&#39;page&#39;]) <= $maxRange ?  
    intval($_GET[&#39;page&#39;]) :  
    (intval($_GET[&#39;page&#39;]) > $maxRange ? $maxRange : 1)) : 1; 
    $previous = $uri ? $uri.($page-1 <= 0 ? 1 : ($page-1 >= $maxRange ? $maxRange-1 :
     $page-1 )) : 
    $_SERVER[&#39;PHP_SELF&#39;].&#39;?page=&#39;.($page-1 <= 0 ? 1 : ($page-1 >= $maxRange ? $maxRange-1 :
    $page-1 )); 
    $next = $uri ? $uri.($page+1 > $maxRange ? $maxRange : $page+1) : $_SERVER[&#39;PHP_SELF&#39;].
    &#39;?page=&#39;.(
    $page+1 > $maxRange ? $maxRange : $page+1); 
    $jump = $uri ? $uri : $_SERVER[&#39;PHP_SELF&#39;].&#39;?page=&#39;; 
    $retval .= $page > 1 ? &#39;<a class="common" href="&#39;.$previous.&#39;" >上一页</a>&#39; : &#39;&#39;; 
    if(empty($_GET[&#39;page&#39;]) || $_GET[&#39;page&#39;] < $displayTab) { 
        $start = 0; 
        $range = $displayTab; 
    }else { 
        $range = !empty($_GET[&#39;page&#39;]) && intval($_GET[&#39;page&#39;]) + ($displayTab/2)  >= $range ? 
        $range : intval($_GET[&#39;page&#39;]) + ($displayTab/2); 
        $start = $range - $displayTab + 1; 
    } 
    for($i= $start; $i <= $range; $i++) { 
            if($i <= 0) continue; 
  $retval .= ((!empty($_GET[&#39;page&#39;]) && is_numeric($_GET[&#39;page&#39;]) ? ($_GET[&#39;page&#39;] > $maxRange ?
    $maxRange : (intval($_GET[&#39;page&#39;]) <= 0 ? 1 : intval($_GET[&#39;page&#39;]))) : 1 ) == $i) ? &#39;
           <a class="current" href="&#39;. $jump.$i .&#39;">&#39;. $i .&#39;</a>&#39; :
             &#39;<a class="common" href="&#39;. $jump.$i .&#39;">&#39;. $i .&#39;</a>&#39;; 
    } 
    $retval .= ($maxRange - (!empty($_GET[&#39;page&#39;]) && is_numeric($_GET[&#39;page&#39;]) ?
     $_GET[&#39;page&#39;] : 1 )) >
     $displayTab ? &#39;<a class="common" href="&#39;. $jump.$maxRange .&#39;">...&#39;. $maxRange .&#39;</a>&#39; : &#39;&#39;; 
    $retval .= (!empty($_GET[&#39;page&#39;]) && is_numeric($_GET[&#39;page&#39;]) ? $_GET[&#39;page&#39;] : 1 ) 
    < $maxRange ? &#39;<div class="jump">
<input id="code" type="text" name="page" size="3" title="输入页码,按回车快速跳转"
 onkeyup="submits(event);">/ &#39;. $maxRange .&#39;页</div>&#39; : &#39;&#39;; 
    $retval .= (!empty($_GET[&#39;page&#39;]) && is_numeric($_GET[&#39;page&#39;]) ? $_GET[&#39;page&#39;] : 1 ) 
    < $maxRange ? &#39;<a class="common" href="&#39;. $next .&#39;">下一页</a>&#39; : &#39;&#39;; 
    $retval .= &#39; 
    <script type="text/javascript"> 
    function submits(e) { 
        var code = document.getElementById(\&#39;code\&#39;); 
        if(code.value != \&#39;\&#39;) { 
            if(code.value.match(/[0-9]{1,}/)) { 
                if(e.keyCode == 13) { 
                    location.href= \&#39;&#39;.$jump.&#39;\&#39; + code.value; 
                } 
            }else{ 
                if(e.keyCode == 13) { 
                    code.value = \&#39;\&#39;; 
                } 
            } 
        } 
    } 
    </script>&#39;; 
    return $retval; 
} 
  
?> 
</body> 
</html>

2. [代码]20111227第一版

<?php  
/**  
*      [WebodMin] (C)2010-2099 Blank Inc.  
*      This is open source code, You can borrow, but can not modify the copyright  
*      Update: 2011-12-27 
**/ 
function multi($num,$limit,$loopvar,$style,$str=&#39;&#39;){     
$count = ceil($num/$limit);     
$loopvar = $count < $loopvar ? $count : $loopvar;     
$_GET[&#39;page&#39;] = !empty($_GET[&#39;page&#39;]) && $_GET[&#39;page&#39;] <= $count ? $_GET[&#39;page&#39;] : 1;     
$str .= $_GET[&#39;page&#39;] > 1 && $_GET[&#39;page&#39;] <= $count ? &#39;<a class="&#39;.$style.&#39;" 
href="?page=&#39;.($_GET[&#39;page&#39;]-1 <=0 ? 1 : $_GET[&#39;page&#39;]-1).&#39;">上一页</a>&#39; : $_GET[&#39;page&#39;] > 1 ? 
&#39;<a class="&#39;.$style.&#39;" href="?page=&#39;.($_GET[&#39;page&#39;]-1 <=0 ? 1 : $_GET[&#39;page&#39;]-1).&#39;">上一页</a>&#39; : false;     
if(empty($_GET[&#39;page&#39;]) || $_GET[&#39;page&#39;] < $loopvar) {         
for($i=0;$i<=$loopvar;$i++) {             
if($i !=0 ) {                 
$str.= $_GET[&#39;page&#39;] == $i ? &#39;<a class="cruuent" href="?page=&#39;.$i.&#39;">&#39;.$i.&#39;</a>&#39; :
 &#39;<a class="&#39;.$style.&#39;" href="?page=&#39;.$i.&#39;">&#39;.$i.&#39;</a>&#39;;               
 }        
  }     
  }
  else{        
   $size = $_GET[&#39;page&#39;]+1 >= $count ? $count : $_GET[&#39;page&#39;]+1;          
   $page = ($size-$loopvar)+1;         
   for($i=$page;$i<=$size;$i++) {             
   if($i !=0 ) {                 
   $str.= $_GET[&#39;page&#39;] == $i ? &#39;<a class="cruuent" href="?page=&#39;.$i.&#39;">&#39;.$i.&#39;</a>&#39; : &#39;
   <a class="&#39;.$style.&#39;" href="?page=&#39;.$i.&#39;">&#39;.$i.&#39;</a>&#39;;               
   }         
   }     
   }     
   $str .= $_GET[&#39;page&#39;] < $count ? &#39;<a class="&#39;.$style.&#39;" href="?page=&#39;.($_GET[&#39;page&#39;]+1 >=$count ?
    $count : $_GET[&#39;page&#39;]+1).&#39;">下一页</a>&#39; : false;     
    $str .=&#39;<a class="countNumber">共:&#39;.$count.&#39;页</a>&#39;;     
    return $str; }  echo multi(150,10,5,&#39;a&#39;); ?> <style> 
    .a {     
    text-align: center;    
     display: block;     
     padding: 5px 10px 5px 10px;    
      margin-right: 5px;    
       float: left;    
        font-size: 13px;    
         color: #000;     
         text-decoration: none;     
         border: 1px solid #c2d5e3;     
         font-family: Tahoma;
          } 
          a:hover {     
          border: 1px solid #000;    
           font-weight:bold; } 
           a.cruuent {     
           text-align: center;     
           display: block;     
           padding: 5px 10px 5px 10px;    
            margin-right: 5px;    
             float: left;     
             font-size: 13px;     
             color: #000;     
             text-decoration: none;    
              border: 1px solid #c2d5e3;    
               font-family: Tahoma;     
               background-color:#e5edf2;     
               font-weight:bold; }
                a.countNumber {    
                 border:none;    
                  text-align: left;    
                   display: block;    
                    padding:5px 5px 0px 5px;    
                     margin-right: 5px;    
                     float: left;     
                     font-size: 13px;     
                     font-weight:bold;    
                      color: #333;     
                      text-decoration: none;    
                       font-family: Tahoma; } 
                       </style>

以上就是PHP分页 upgrade 20130125的内容,更多相关内容请关注PHP中文网(www.php.cn)!


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn