#3: Creating Previous/Next Links

If you need to display a large number of items on a page, you may want to simplify the display by breaking it into several pages with a limited number of items per page. By doing so, you make your results easier to view and speed page-loading times.

A navigation bar gives the users control of these pages. You want a bar with Previous and Next links, as well as direct page number links. Here's a script that does it all:

<?php function create_navbar($start_number = 0, $items_per_page = 50, $count) { // Creates a navigation bar $current_page = $_SERVER["PHP_SELF"]; if (($start_number < 0) || (! is_numeric($start_number))) { $start_number = 0; } $navbar = ""; $prev_navbar = ""; $next_navbar = ""; if ($count > $items_per_page) ...

Get Wicked Cool PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.