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! |
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. 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!
|
|
|
|
Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
|
|
|
|
Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization. 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!
|
|
|
|
XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. 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!
|
|
|
|
Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
|
|
|
|
Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |