Navigation Usability
  Home arrow Navigation Usability arrow Page 3 - Using Multiple Pages for Navigation
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 
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? 
NAVIGATION USABILITY

Using Multiple Pages for Navigation
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2002-09-08

    Table of Contents:
  • Using Multiple Pages for Navigation
  • Recap
  • Setting up variables
  • Displaying links
  • Final Script

  • 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


    Using Multiple Pages for Navigation - Setting up variables


    (Page 3 of 5 )

    Now let's jump right into navigation. The variable $start is a place marker in the array. Since we know PHP arrays start with "0," and we really don't want to call the first item "0," we have to get a number your users might feel more comfortable with. We can't assign the variable $start, since it's used further in the script, so since we really start counting at "1," let's just add 1 to the start point:

    <?php
    $realstart 
    = ($start 1);
    ?>

    We'll use $realstart later, but first, we need to set some other variables. We know each page is going to display $display items, so we also know the last item on each page is going to be $start + $display. Remember, $realstart is just the number we are showing our users, not its actual value in the array, therefore we use $start instead of $realstart.

    <?php
    //set last item number on this page
    $finish = ($start $display);
    ?>

    Now we find out how many items exist in the file. In order to do this, we use the count() function. It's one of the easiest PHP functions and also one of the must useful.

    <?php
    //find out how many items are in the array 
    $keys count($data);
    ?>

    Now that we know how many items are in the array ($keys), we can find out how many pages there should be. We can determine this by dividing the number of items by the number per page. Since there are $display items on each page, we can write this:

    <?php
    //determine number of pages
    $newspages = ($keys $display);
    ?>

    Now for some error prevention. If there are, say 28 items, page 3 will show 21-30. In order to fix this, we'll simply check the $finish variable. Since we know how many items are in the array, if $finish is greater than the count of the array, well reset $finish.

    <?php
    //display max number correctly.  
    if ($finish &gt$keys) { 
        
    $finish $keys; }
    ?>

    More Navigation Usability Articles
    More By Codewalkers


       · I think there was a mistake in this tutorial, because it didn't work for me until I...
       · Fixed, and now working fine. :)[code]<?PHP$page = $_GET['page'];// if a...
       · << previous ||displaying 26 - 30 of 54The script displays only 30 of the 54...
     

    NAVIGATION USABILITY ARTICLES

    - Advanced Bulleted-List Menu
    - Using Multiple Pages for Navigation





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT