PHP
  Home arrow PHP arrow Page 4 - Previous or Next? Paginating Records with PHP, part 1
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
Google.com  
PHP

Previous or Next? Paginating Records with PHP, part 1
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 22
    2005-04-26


    Table of Contents:
  • Previous or Next? Paginating Records with PHP, part 1
  • The first step: paginating records in a procedural way
  • A deeper look at the "paginatetRecords()" function
  • Putting the "paginateRecords()" function into action: procedural record paging

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Previous or Next? Paginating Records with PHP, part 1 - Putting the "paginateRecords()" function into action: procedural record paging
    ( Page 4 of 4 )

    Let's jump straight in and test out our recently developed "paginateRecords()" function. With three lines of code, we're ready to paginate records on our Web pages. Here's a possible regular implementation:

    <html>

    <head>

    <title>PAGINATING DATA WITH PHP</title>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    </head>

    <body>

    <p>Record Listing</p>

    <?php

    require_once('pager.php');

    $page=$_GET['page'];

    echo paginateRecords('data.dat',$page);

    ?>

    </body>

    </html>

    Let's be honest. The required code to make record paging is extremely short and understandable. We've just included the file that contains the function and invoked it, passing in the parameters the data file to be read and the page pointer to display the records. Just give it a try and add your own improvements. Simple and straightforward, isn't it?

    However, there are some issues to be considered about this approach.  This solution might be suitabel for small websites, where you can live quite happily delivering content from simple text files. With larger applications, however, and with heavy loads and more demanding requirements, this approach falls short. What's more, we're mixing HTML markup with PHP code, which is not recommended at all.

    So, can we do it any better? You bet. We must improve this technique by developing a solution definitely more portable for larger websites, and able to deal with a relational database system such as MySQL. That will be our next step in the paging record process.

    Summarizing and further improvements

    In this first part, we looked at a simple PHP function for paginating records extracted from a flat text file. Also, we saw how simply it can be implemented, with just a few lines of code. Of course, this procedural method supports many possible improvements, being a handy introduction to paging techniques. If you're already working with Web applications that require recordset paging very frequently with minor headaches, just take the function and play with it to meet your needs.

    In the coming second part, we'll look at a mature OOP approach, defining a PHP class to efficiently handle recordset paging processes, considerably more suitable for larger applications. It sounds very promising. We have the tools and the knowledge for developing such a class. So, get ready for the next part, and stay tuned!



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek