Webune Forums How To Make Page Links For Each Pages How To Make Page Links For Each Pages Webune Forums How, To, Make, Page, Links, For, Each, Pages Webune Forums Announcements CSS Dedicated Hosting Domain Names Espanol FTP General Errors HTML Javascipt Linux Hello, welcome to Webune Web Hosting. We provide PHP hosting a low prices. If you have a website and want PHP, Webune has many plan options to meet your needs.

today we are going to show you how to make links for each page. for example, have you noticed when you google something, at the bottom there is always links for each page like for page 1, page 2 etc...

Using PHP you can accomplish this. we are going to use a function to make it easy.

so what do you need for this, you are going to need PHP on your website for this script to work. first, open a text editor. i am using a windows xp computer so i will use notepad. open a blank notepad and copy and paste the following code:
<div style="float:left;padding-left:10px;">
	<a href="http://www.webune.com">
		<img src="http://www.webune.com/images/headers/default_logo.jpg" border="0" align="Webune Logo">
	</a>
</div>
<h1 style="float:left">Webune Pagination Function</h1>
<div style="clear:left;"></div>
<hr />
<?php
##################################
# YOU CAN CONFIGURE THIS #
$num_of_items = 200;
$items_per_page = 9;
$max_links = 10;
# END CONFIGURATION #
#################################
if($_GET['page_num']){
	$page_num = $_GET['page_num'];
}else{
	$page_num = 1;
}
?>
<h1>This Is Page: <span style="color:#F00;"># <? echo $page_num; ?></span></h1>
<strong>example:</strong> <br>
<strong>number of items</strong> = <? echo $num_of_items; ?><br>
<strong>number of items per page</strong> = <? echo $items_per_page; ?><br>
<strong>number of links per page</strong> = <? echo $max_links; ?><br>
<?php
 ###### START PAGINATION FUNCTIONS ###### 
function pagination_link($id, $page_num){
	return $_SERVER['PHP_SELF'].'?page_num='.$page_num;
}
function pagination($num_of_items, $items_per_page, $id, $page_num, $max_links){
 	$total_pages = ceil($num_of_items/$items_per_page);
 	if($page_num) {
 		if($page_num >1){ 
 			$prev = ' &nbsp; <a href="'.pagination_link($id, ($page_num -1 )).'">&lt; PREV</a> &nbsp; '; 
 			$first = '<a href="'.$_SERVER['PHP_SELF'].'">&lt;&lt; First Page</a>'; 
 		}
 	}
	 if($page_num <$total_pages){ 
		$next = ' &nbsp; <a href="'.pagination_link($id, ($page_num+1)).'">NEXT &gt;</a> &nbsp; '; 
		$last = ' &nbsp; <a href="'.pagination_link($id, $total_pages).'">Last Page &gt;&gt;</a> &nbsp; ';
	 }
	 echo $first;
	 echo $prev;
	 $loop = 0;
	 if($page_num >= $max_links) {
		$page_counter = ceil($page_num - ($max_links-1));
	 }else{
		$page_counter = 1;
	 }
	 if($total_pages < $max_links){
		$max_links = $total_pages;
	 }
	 do { 
		if($page_counter == $page_num) {
			echo ' &nbsp; <strong>'.$page_counter.'</strong> &nbsp; '; 
		}else{
			echo '<a href="'.pagination_link($id, ($page_counter)).'">'.$page_counter.'</a> &nbsp; ';
		} 
		$page_counter++; $current_page=($page_counter+1);
		$loop++;
	 }while ($max_links > $loop);
	 echo $next;
	 echo $last;
}

?>
<div align="center">
<?php
 pagination($num_of_items, $items_per_page, $id, $page_num, $max_links)
 ?> 
</div><br>
<br>
<div style="width:400px;">Thank you for trying out this tutorial. 
We hope you have learned to create a pagination and 
how you can make links for each page 
<a href="http://www.webune.com">Click HerE For More Tutorials</a></div>

now save it as "pagination.php" {NOTE: be sure to also put the quotes so that notepad saves the file correctly, otherwise, it may save it as pagination.php.txt and we dont need the .txt at the end] now upload to your website which has PHP and test run it so see how it work.

we hope you liked this pagination php function. there are other ways to make page links for example, you can have pagination in jsp and also make javascript pagination, even pagination on wordpress. you can also have static pagination in css i have seen pagination in some joomla sites which use pagination in rails. next we are going to make ajax pagination. Ajax is more advanced because it uses javascript and PHP. visit us soon for an update.