Php Programming Code Examples
Php > Site Navigation Code Examples
Another Paging with Stage
Another Paging with Stage
<?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;
}
}
}
};
?>