Site Navigation Code
  Home arrow Site Navigation Code arrow Page numbers
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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 numbers
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2003-07-01

    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


    This script enables you to create page number links and previous / next links.
    It is useful when displaying search results or large amount of data.
    It also allows user to choose how many records to display per page.


    By : tebrino

    <?php
    /*
    This script enables you to create page number links and previous / next links.
    It is useful when displaying search results or large amount of data.
    It also allows user to choose how many records to display per page.
    To use it simply replace MySQL queries with your own. With small changes
    you can use it with any database server.
    To use it simply edit the config part and line marked with text &quot;EDIT ME&quot; and that's it. Enjoy.
    If you have any questions, comments, or if you find any bugs please feel free to contact me:
    Author: Ilir Fekaj
    Contact: tebrino@hotmail.com
    Website / live demo: http://www.freemidi.breezeland.com/page_numbers.php
    Created: July 01. 2003.
    Modified: July 02. 2003.
    Version: 1.0.1
    If you like it, use it, you can also give me a credit.
    */

    // config-------------------------------------
    $host = "localhost"; //your database host
    $user = "username"; // your database user name
    $pass = "password"; // your database password
    $db = "database_name"; // your database name

    $filename = "your_file_name.php"; // name of this file
    $option = array (5, 10, 25, 50, 100, 200);
    $default = 25; // default number of records per page
    $action = $_SERVER['PHP_SELF']; // if this doesn't work, enter the filename
    $query = "SELECT title, url FROM table_name ORDER BY title"; // database query. Enter your query here
    // end config---------------------------------

    $opt_cnt = count ($option);

    $go = $_GET['go'];
    // paranoid
    if ($go == "") {
    $go = $default;
    }
    elseif (!in_array ($go, $option)) {
    $go = $default;
    }
    elseif (!is_numeric ($go)) {
    $go = $default;
    }
    $nol = $go;
    $limit = "0, $nol";
    $count = 1;


    echo "<form name=\"form1\" id=\"form1\" method=\"get\" action=\"$action\">\r\n";
    echo "<select name=\"go\" id=\"go\">\r\n";

    for ($i = 0; $i <= $opt_cnt; $i ++) {
    if ($option[$i] == $go) {
    echo "<option value=\"".$option[$i]."\" selected=\"selected\">".$option[$i]."</option>\r\n";
    } else {
    echo "<option value=\"".$option[$i]."\">".$option[$i]."</option>\r\n";
    }
    }

    echo "</select>\r\n";
    echo "<input type=\"submit\" name=\"Submit\" id=\"Submit\" value=\"Go\" />\r\n";
    echo "</form>\r\n";

    $connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect");
    mysql_select_db ($db) or die ("Unable to select database $db");


    // control query------------------------------
    /* this query checks how many records you have in your table.
    I created this query so we could be able to check if user is
    trying to append number larger than the number of records
    to the query string.*/
    $off_sql = mysql_query ("$query") or die ("Error in query: $off_sql".mysql_error());
    $off_pag = ceil (mysql_num_rows($off_sql) / $nol);
    //--------------------------------------------

    $off = $_GET['offset'];
    //paranoid
    if (get_magic_quotes_gpc() == 0) {
    $off = addslashes ($off);
    }
    if (!is_numeric ($off)) {
    $off = 1;
    }
    // this checks if user is trying to put something stupid in query string
    if ($off > $off_pag) {
    $off = 1;
    }

    if ($off == "1") {
    $limit = "0, $nol";
    }
    elseif ($off <> "") {
    for ($i = 0; $i <= ($off - 1) * $nol; $i ++) {
    $limit = "$i, $nol";
    $count = $i + 1;
    }
    }

    // Query to extract records from database.
    $sql = mysql_query ("$query LIMIT $limit") or die ("Error in query: $sql".mysql_error());

    while ($row = mysql_fetch_object($sql)) {
    // EDIT ME. Edit the line below to match your own table. Just replace $row->url with $row->your_table_column
    echo "$count. <a href=\"$row->url\">$row->title</a><br />\r\n"; // this is example, you may enter here anything you like
    $count += 1;
    }
    echo "<br /><br />\r\n";
    if ($off <> 1) {
    $prev = $off - 1;
    echo "[ &lt; <a href=\"$filename?offset=$prev&amp;go=$go\">prev</a> ] \r\n";
    }
    for ($i = 1; $i <= $off_pag; $i ++) {
    if ($i == $off) {
    echo "[<b> $i </b>] \r\n";
    } else {
    echo "[ <a href=\"$filename?offset=$i&amp;go=$go\">$i</a> ] \r\n";
    }
    }
    if ($off < $off_pag) {
    $next = $off + 1;
    echo "[ <a href=\"$filename?offset=$next&amp;go=$go\">next</a> &gt; ] \r\n";
    }

    echo "<br /><br />\r\n";
    echo "Page $off of $off_pag<br />\r\n";
    ?>
    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!


    Build Forge Express demo: Enabling software delivery excellence for small and midsized businesses

    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!


    NEW! Driving Business Success with Rational Process Library

    Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance.
    FREE! Go There Now!


    NEW! A Layered approach to delivering security-rich Web applications

    As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper.
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! IBM Enterprise Modernization Sandbox for System z: Architecture

    Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server.
    FREE! Go There Now!


    NEW! Rational 'Talks to You' Teleconference Series

    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!


    NEW! The dirty dozen: preventing common application-level hack attacks

    As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications.
    FREE! Go There Now!


    NEW! Try IBM Rational Asset Manager V7.0 online!

    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!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Whitepaper: Delivering SOA solutions: service lifecycle management

    The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable.
    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-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek