Zend - The PHP Company




Menus & Navigation

Add Code


myPaging with Staging  

Type: code fragment
Added by: hermawan
Entered: 11/11/2002
Last modified: 01/11/2001
Rating: - (fewer than 3 votes)
Views: 5788
This script is not actually a class. I just want to show you how to make paging with result set and how to display it not all of the link page, but separate it in some number of stage. It can be easly adapted to your general class.


<?php 
  
class paging 
    function 
paging () { 
      
$this->rowperpage 50
      
$this->pageperstg 20
    } 
    function 
getPaging($rownum$pg="1"$stg="1") { 
      
$arr explode("&",$_SERVER["QUERY_STRING"]); 
      if (
is_array($arr)) { 
        for (
$i=0;$i<count($arr);$i++) { 
          if (!
is_int(strpos($arr[$i],"pg=")) && !is_int(strpos($arr[$i],"stg=")) && trim($arr[$i]) != ""$qs .= $arr[$i]."&"
        } 
      } 
      if (
$this->rowperpage<$rownum) { 
        
$allpage ceil($rownum/$this->rowperpage); 
        
$allstg  ceil($allpage/$this->pageperstg); 
        
$minpage = (($stg-1)*$this->pageperstg)+1
        
$maxpage $stg*$this->pageperstg
        if (
$maxpage>$allpage$maxpage $allpage
        if (
$allpage>1) { 
          
$rtn  "<table width=100% align=center cellpadding=2 cellspacing=0><tr align=center valign=middle><td class="smallbody">"
          if (
$stg>1$rtn .= "<a href="".$_SERVER["PHP_SELF"]."?".$qs."pg=".($minpage-1)."&stg=".($stg-1)."">Previous Stage</a> | "
          if (
$pg>1) { 
            if (
$pg==$minpage) { 
              
$rtn .= "<a href="".$_SERVER["PHP_SELF"]."?".$qs."pg=".($pg-1)."&stg=".($stg-1)."">Previous</a> | "
            } else { 
              
$rtn .= "<a href="".$_SERVER["PHP_SELF"]."?".$qs."pg=".($pg-1)."&stg=$stg">Previous</a> | "
            } 
          } 
          for (
$i=$minpage;$i<=$maxpage;$i++) { 
            if (
$i==$pg) { 
              
$rtn .= "<b>$i</b> | "
            } else { 
              
$rtn .= "<a href="".$_SERVER["PHP_SELF"]."?".$qs."pg=$i&stg=$stg" title='Page $i'>$i</a> | "
            } 
          } 
          if (
$pg<=$maxpage) { 
            if (
$pg==$maxpage && $stg<$allstg) { 
              
$rtn .= " <a href="".$_SERVER["PHP_SELF"]."?".$qs."pg=".($pg+1)."&stg=".($stg+1)."">Next</a> | "
            } elseif (
$pg<$maxpage) { 
              
$rtn .= " <a href="".$_SERVER["PHP_SELF"]."?".$qs."pg=".($pg+1)."&stg=$stg">Next</a> | "
            } 
          } 
          if (
$stg<$allstg$rtn .= "<a href="".$_SERVER["PHP_SELF"]."?".$qs."pg=".($maxpage+1)."&stg=".($stg+1)."">Next Stage</a> | "
          
$rtn substr($rtn,0,strlen($rtn)-3); 
          
$rtn .= "</td></tr></table>"
          return 
$rtn
        } 
      } 
    } 
  }; 
?> 


Usage Example




Rate This Script





Search



This Category All Categories