Jump to content
xisto Community
Sign in to follow this  
asglu

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

Recommended Posts

<?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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.