You are seeing this very light version of the page, as you are using an outdated browser!

Onlinetools.org is done in XHTML 1.0 and supports CSS 2.0, please upgrade your browser if you want a better version of this site.

Thank you, please help us developers keep up with the industry rather than patching our code for outdated applications.

open or close right navigation

Previous and Next links demystified

Advertisement:
 
written by:Christian Heilmann on 12.05.2002
Jump to page: 1  2  3  or read all on one page
 

The issue with Previous and Next links

"Previous" and "next" links are one of the necessary evils any middleware developer has to script sooner or later.

Whenever you display a lot of elements of a list, like news, entries in a guestbook, or search results, it's a good idea to limit the displayed items to a certain number per page.

Not only to avoid long rendering times, but also to make it easier for the user to scan for his desired item and to prevent scrolling.

Ok, we need them, let's do them. First thing you do is to analyse the logic behind "previous" and "next" links.

  1. Define how many elements to display on a page.
  2. IF you are NOT on the first page, display the "previous" link, which sets the start of the display to the current start minus the defined number of elements.
  3. Display the amount of elements defined beforehand, making sure that there are enough to display on the last page.
  4. IF there are still more elements in the list to display, define that this is not the last page.
  5. display the next link, which increases the start of the display by the defined number, unless you are on the last page

There are loads of solutions for this issue, most of them using a lot of "if" and "else" statements. Especially displaying the elements while making sure that there are still some, and checking that the start of the "next" link does not exceed the number of available elements can be quite a headache.

Unless you use some of the beautiful functions of PHP that do almost all the necessary comparisons for you.

more»
Table of contents:

The issue with Previous and Next links
PHP to the rescue
The whole script

Back to top

Search:

 

Font:

Click to decrease fontsizeClick to increase fontsize

Text-colour:


Background:


sponsored by :

NWU

Help Onlinetools.org

Help onlinetools.org, donate via paypal

Partners

easyPHP

icons

Link to us

copy the code here:


Powered by EasyCMS