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.
By : hermawan
<?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;
}
}
}
};
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Site Navigation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process. FREE! Go There Now!
|
|
|
|
Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
|
|
|
|
Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today! FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered! FREE! Go There Now!
|
|
|
|
You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |