O'Reilly logo

Wicked Cool PHP by Brian Ward, William Steinmetz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

#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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required