Left Quote    Every day I get up and look through the Forbes list of the richest people in America. If I
- Robert Orben    
Right Quote
[login] | [Register]

Pagination with PHP

by: bs0d
Page: 5 of 6
(View All)

Pages in between

Getting back on track, we will now display the pages in between (not previous or next). To do so, we will use a for loop. View the code below:

This is a basic for loop structure, where it will loop until it is less than or equal to the value of $total_pages. Inside the for loop, we set a condition that if $a equals the current page, to just echo that value, not linked (because we're already on that page). If not, echo the rest of the pages, linked.

Next Page

Displaying the next page link is identical to displaying the previous page link. Your code should look a bit like this:

Set the value of next page in the $next_page variable by taking the value of the current page ($page) and adding 1. Now, we have the condition that will be executed and display the back link only if $next_page is less than or equal to the value of $total_pages. That is all for displaying the paginated links.


I would like to bring important information to your attention. If your category names contain spaces, like, "visual basic" when you try to use that in your link, it will not link properly. Because, it will only read until the space is encountered, and then stops. Your link would read, "visual" instead. Therefore, we will use the function, urlencode(); to replace those spaces so that the browser can interpret them. See the code below,

Simple as that. Now, if $cat was, "visual basic" it is now "visual+basic" and the links will be valid, and browser friendly. Just be sure to place this line of code before the code where you begin to display the links.

1  |  2  |  3  |  4  |  5  |  6  |  
Next »

No Comments for this page.

You Must be logged in or a member to comment.

Tutorial Stats

Tutorial Stats

7 Total Comments
4 Rating of 5 (1 Votes)


Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article



· Simple PHP Tutorial
· One File Website
· Building a Comments Script
· Complete Members System
· Variable Scope

"" Copyright © 2002-2021; All rights lefted, all lefts righted.
Privacy Policy