Site Navigation Code
  Home arrow Site Navigation Code arrow Page Lister Class
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
SITE NAVIGATION CODE

Page Lister Class
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-01-18

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Limit the number of returns you get from a MySQL Query and printout navigation links to each of the pages. This was adapted from and performs exactly like nsfmc's in-line code

    By : flight553

    <?php

    /*
    mysql_pager.php
    class by operator@superprivate.com 2001/02/02 12:00
    based on in-line code written by marcos(@)generic.cx on 2000/08/29
    distributed under the Gnu Public License

    just require the class and make a new object, passing in:
    the mysql_query() result,
    the variable $page,
    and the number of results per page you want.
    example at the bottom of this file

    There's $10/month PHP4-MySQL hosting with SSH, telnet, gpg, perl at http://missoulaweb.com

    */

    class mysql_pager {

    // define properties
    var $page;
    var $result;
    var $results_per_page = 3;
    var $total_pages;

    /*
    Define the methods

    1st method is the constructor, which has the same name
    as the class and is called on every instantiation of the class

    pass in the query result handle, current page number and integer how many results per page
    like: $f->mysql_pager($result, 1, 15);
    */

    function mysql_pager( $result, $current_page, $results_per_page ) {

    if(!$result){ # Bogus Query, or mysqld isn't running...
    echo "<div align=center>Either the database is down, or the query was invalid.</div>\n";
    return;
    }

    $this->result = $result;

    if(!$current_page || $current_page < 0)
    $this->page = 1;
    else $this->page = $current_page;

    if(!empty($results_per_page))
    $this->results_per_page = $results_per_page;

    $numrows = @mysql_num_rows($this->result);
    if(!$numrows) {
    echo "<div align=center>No results for that query.</div>\n";
    return;
    }

    $this->total_pages = ceil($numrows / $this->results_per_page);
    # how many pages you WILL get.
    } // end constructor function

    function print_paged_results() {
    /*
    echo "Current Page: ". $this->page ."<br>".
    "Results per Page: ". $this->results_per_page ."<br>";
    */
    echo "<table border=0 align=center>\n";
    $start = ($this->page - 1) * $this->results_per_page;
    mysql_data_seek($this->result, $start); #Moves the pointer to right row

    $x = 0;
    for($i = 1; $i <= $this->results_per_page && $row = @mysql_fetch_array($this->result); $i++) {
    if($x++ & 1) $bgcolor = "#F2F2FF";
    else $bgcolor = "#EEEEEE";

    echo "<tr bgcolor=$bgcolor><td>". $row["lastactiondate"] . "</td></tr>";
    // edit this part to spit out whatever html you want

    } // end for loop

    echo "</table>\n";
    } // end function print_paged_results


    function print_navigation() {
    global $PHP_SELF;

    echo "<div align=center>";

    for($i = 1; $i <= $this->total_pages; $i++) { #loop to print << 1 2 3... $total_pages >>
    if($i == 1 && $this->page > 1) #Prints the << first to goto the previous page (not on page 1)
    echo "<a href=\"$PHP_SELF?page=".($this->page - 1)."\" onMouseOver=\"status='Previous Page';return true;\" onMouseOut=\"status=' ';return true;\">&#0171;&nbsp;</a>";

    if($i == $this->page) #Doesn't print a link itself, just prints page number
    echo "<font color=\"#ff3333\">&nbsp;$i&nbsp;</font>";

    if($i != $this->page) #Other links that aren't this page go here
    echo "<a href=\"$PHP_SELF?page=$i\" onMouseOver=\"status='Go to Page $i';return true;\" onMouseOut=\"status=' ';return true;\">&nbsp;$i&nbsp;</a>";

    if($i == $this->total_pages && $this->page != $this->total_pages) # Link for next page >> (not on last page)
    echo "<a href=\"$PHP_SELF?page=".($this->page + 1)."\" onMouseOver=\"status='Go to the Next Page';return true;\" onMouseOut=\"status=' ';return true;\">&nbsp;&#0187</a>";
    } // end for

    echo "</div>\n";
    } // end function print_navigation

    } // end class definition

    /*
    mysql_connect($server, $uname, $pass );
    mysql_select_db("$db");

    $result= @mysql_query("SELECT * FROM table");

    $p = new mysql_pager( $result, $page, 10 );
    // the variable $page will be created by the output and passed back
    // in as a GET var when you click any of the navigation links

    $p->print_navigation();
    $p->print_paged_results();
    $p->print_navigation();
    }
    */
    ?>
    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

     

    IBM® developerWorks developerWorks - FREE Tools!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    NEW! Best practices for software analysis: An introduction to the IBM Rational Software Analyzer application

    This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer.
    FREE! Go There Now!


    NEW! Best Practices in Integrated Requirements Management

    Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right."
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Developer for System i V7.1

    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!


    NEW! Evaluate Rational Host Access Transformation Services (HATS) Toolkit V7.1

    Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications.
    FREE! Go There Now!


    NEW! Evaluate WebSphere Extended Deployment Compute Grid V6.1

    Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points.
    FREE! Go There Now!


    NEW! Rational Talks to You: Manage RUP-based CMMI initiatives

    Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered!
    FREE! Go There Now!


    NEW! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!


    NEW! Webcast: Introducing the new Information Server and Solutions community: LeverageInformation

    User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    SITE NAVIGATION CODE ARTICLES

    - Simple Menu System
    - Simply image viewer script
    - Simple File Lister
    - Dynamic Error Pages
    - BSoftEditor
    - Yahoo Status
    - Page numbers
    - PHP Search Navigator 1.0
    - Simple Page Navigation
    - An easy page browser ( prev 6 7 8 9 10 next )
    - AutoIndex PHP Script (Directory Indexer)
    - Bs_HtmlNavigation (Navigation and Sitemap cl...
    - Another Paging with Stage
    - Website Navigation via PHP
    - MySQL Paging Class






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway