Navigation Usability

  Home arrow Navigation Usability arrow Page 4 - Using Multiple Pages for Navigation
NAVIGATION USABILITY

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

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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    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

    blog comments powered by Disqus

    NAVIGATION USABILITY ARTICLES

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


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap