HOME       >>       Programming

PHP Function To Add Previous and Next Page Feature useful php function


asglu

<?php function navigationbar($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) { $nav_count = 0; $page_count = 1; $nav_passed = false; while ($nav_count < $count) { // Are we at the current page position? if (($start_number <= $nav_count) && ($nav_passed != true)) { $navbar .= "<b><a href=\"$current_page?start=$nav_count\"> [$page_count] </a></b>"; $nav_passed = true; // Do we need a "prev" button? if ($start_number != 0) { $prevnumber = $nav_count - $items_per_page; if ($prevnumber < 1) { $prevnumber = 0; } $prev_navbar = "<a href=\"$current_page?start=$prevnumber\"> <<Prev - </a>"; } $nextnumber = $items_per_page + $nav_count; // Do we need a "next" button? if ($nextnumber < $count) { $next_navbar = "<a href=\" $current_page?start=$nextnumber\"> - Next>> </a><br>"; } } else { // Print normally. $navbar .= "<a href=\"$current_page?start=$nav_count\"> [$page_count] </a>"; } $nav_count += $items_per_page; $page_count++; } $navbar = $prev_navbar . $navbar . $next_navbar; return $navbar; }} ?>

I added comment to make you understand about this PHP function

gogoily

Thank you very much.It'll work better if you change it into a Class.


ahsankhatri

Thnx So Much buddy

 

but it need to be more secur i guess


kudmus

It'll work better if you change it into a Class.

I'm learning PHP and would appreciate it if you explain what you are talking about here. Please be clear and help dummies. I'm sure there are a lot of guys like me out there who have heard about classes but would like to know how you do it in a case like this.

Athleone

This is an interesting and useful piece of code. However, I know nothing about classes so I cannot help you with that bit. Sorry!-Athleone


galexcd

I'm learning PHP and would appreciate it if you explain what you are talking about here. Please be clear and help dummies. I'm sure there are a lot of guys like me out there who have heard about classes but would like to know how you do it in a case like this.

A class is basically a piece of code that can be stored as an object in memory. It can be very useful if you want to be able to store a variety of data in one variable, and you want to modify the data easily by running methods.

You can read up on Object Oriented programming in PHP here.


VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.