SunQuest
 
       Navigation Usability
  Home arrow Navigation Usability arrow Page 4 - Using Multiple Pages for Navigation
Try It Free
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 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
IBM developerWorks
 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
     
    Try It Free
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Using Multiple Pages for Navigation - Displaying links


    (Page 4 of 5 )

    Now it gets a little more complicated. We don't want a "previous" link if we're on page 1. We also know anything less than page 1 has been given a value of 1 by notepad's script. If we are on page 2 or higher, we want a "previous" link. So let's take a look at the script and then break it down:

    <?php
    if ($page &gt1) { 
    ?&
    gt;
        &
    lt;a href="&lt;?=$PHP_SELF;?&gt;?page=&lt;?=($page - 1);?&gt;"&gt;previous&lt;/a&gt; || 
    &
    lt;?PHP }
    ?>

    What are we looking at? First we're saying to only run our script if the page is above 1, since we don't want a previous link on page 1. If the page is greater than 1, though, we're going to make a link called "previous" than point to this page, or $PHP_SELF, where the page is equal to the $page variable minus one. If $page was set to 2 and the file was, say, news.php, the output would be <a href="news.php?page=1">previous</a>. I like to add a little << before the link to make it graphically pleasing.

    Now we do the same for the "next" link. Instead of subtracting 1, we're going to add 1. But when should we run it? Since we've set the number of pages total to $newspages, we should run it only when $page is less than $newspages.

    <?php
    if ($page &lt$newspages) { 
    ?&
    gt;
        &
    lt;a href="&lt;?=$PHP_SELF;?&gt;?page=&lt;?=($page + 1 );?&gt;"&gt;next&lt;/a&gt; &gt;&gt;  
    &
    lt;?php }
    ?>

    Notice I added a >> as mentioned above. Between these links, typically, I like to see what items I'm viewing, so we need another line:

    <?php
    echo "displaying items " $realstart " through " $finish;
    ?>

    We've already defined what $realstart is. One page 1, it's going to be 1 and on page 2, (if your $display is set to 5) it will be 6. Sometimes, you might want to add the following line for good measure:

    <?php
    echo "&lt;br /&gt;" $keys " items total";
    ?>

    $keys, of course, is the total number of items in the news file.

    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 2 hosted by Hostway