pagination script how to create page numbers links function php

Mobile
feeds
Welcome Login | Register

pagination script how to create page numbers links function php
Reply Your Comments:
Click this button if you are interested in replying to this topic and leave your comments
Sent To Friend
CLick this button if you want to send this page to a friend.
Subsribe To Rss Feeds
Subscribe to RSS
CLick this button if you want to subscribe to this RSS Feed. You can use your browsers feeds burners if you have mozilla or internet explorer 7 or higher and keep up with updates.
  Forums Index
      » PHP Forums
        » » pagination script how to create page numbers links function php
pagination script how to create page numbers links function php
Post Description: pagination script how to create page numbers links function php PHP
Post Tags:
This Post Has Been Viewed 1528 Times Since Mon Feb 18, 2008 11:00 pm Author hostman with 10 replies
pagination script how to create page numbers links function php
Advertise On This Page




Welcome to Wallpaperama Forums, This script was provided by our friend at Webune.com - Webune specialize in Web Hosting for Individual just like you. To enhance our service we provide helpful tutorials to help you make your scripting easier. this short tutorial is to show you how you can make a simple pagination script with a function, this function will create a pagination menu, similar to the one found here at wallpaperama.


each number page will have a link using the GET method in url


lets say for example i have a forums, and for each topic i want to show only 20 replies per page. so lets say i have a forums topic with 200 replies, so if you do that math, i should end up with 10 pages.


now all you have to do to see this script in action, is copy and paste to your text editor like notepad. then save it as webune-pagination.php and upload to your website, then open it in your browser and you will see how it works.


Thanks to the folks at www.webune.com for their support on this.


webune-pagination.php this function will create a pagination menu, similar to the one found here at wallpaperama.

each number page will have a link using the GET method in url

lets say for example i have a forums, and for each topic i want to show only 20 replies per page. so lets say i have a forums topic with 200 replies, so if you do that math, i should end up with 10 pages.

now all you have to do to see this script in action, is copy and paste to your text editor. then save it as webune-pagination.php and upload to your website, then open it in your browser and you will see how it works.

Thanks to the folks at www.webune.com for their support on this.

webune-pagination.php
<?php
# THIS FUNCTION CREATED THE URL
function pagination_link($id, $page_num){
	return $_SERVER['PHP_SELF'].'?page_num='.$page_num;
}
###### PAGINATION FUNCTION ###### 
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'].'">First Page &lt;&lt;</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;
}
?>
<h1>PAGINATION SCRIPT BY <a href="http://www.webune.com">WWW.WEBUNE.COM</a></h1>
<?php
#################################
# Please Do Not Remove
# SCRIPT CREATED BY WEBUNE.COM
#################################
# CONFIGURATION EXAMPLE
$num_of_items = 200;
$items_per_page = 9;
$max_links = 10;

if($_GET['page_num']){
	$page_num = $_GET['page_num'];
} else {
	$page_num = 1;
}
?>
<h1>PAGE: <?php echo $page_num; ?></h1>
<strong>example:</strong> <br>
<strong>number of items</strong> = <?php echo $num_of_items; ?><br>
<strong>number of items per page</strong> = <?php echo $items_per_page; ?><br>
<strong>number of links per page</strong> = <?php echo $max_links; ?><br>
<div align="center">
	<?php echo pagination($num_of_items, $items_per_page, $id, $page_num, $max_links); ?> 
</div><br><br>
<div align="center"><a href="http://www.webune.com">PHP/MYSQL WEB HOSTING<br>
<img src="http://www.webune.com/images/headers/default_logo.jpg" border="0"></a></div>





hope this helps, please provide any comments, whether be good or bad




Leave Your Comments

Your Name
Your Email Address (Will Not Be Published)
Notify Me When Someone Replies to this Page
(An email will be sent to you when someone replies to your comments)
Your Comments
Include A Picture with your comments
Share
| More
Share this page by putting this URL in your comments to other websites like myspace, Facebook, Twitter friendster, Hi5, Groups, Boards, Forum or others. Just Copy and Paste this Code
URL:
To embed this topic, just copy the code from the "Embed" box. Once you've copied the code, just paste it into your website or blog to embed it.
Embed:
BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums
BBCODE:
Subscribe Feeds
Webmasters - Exchange Links With Us. Add related websites to this topic
Add Link:
Links Related to : pagination script how to create page numbers links function php

Comments and replies About pagination script how to create page numbers links function php
:: 1 :: Reply #58879 Reply By Joe On Sun Jun 22, 2008 5:50 pm
Joe:
hi,

i'm trying to use your webune-pagination.php script for my website. i added it to the bottom of one of my pages and it seems to work as far as showing up and everything. i don't really know much about php.

how dose it work? i've only got one page in the directory but i want to add allot more. how should i name the pages? i'm i suppose to include a page number or something or does it work by using the same page only changing the products? or dose it just cycle through the pages in that directory?

thank you

joe




:: 2 :: Reply #67166 Reply By Sean On Mon Aug 18, 2008 8:38 pm
Sean:
thanks for the script thats exactly what i was looking for. found your site via google.
thanks,
sean gallagher
(atlwebsite )
:: 3 :: Reply #69406 Reply By amit On Thu Sep 04, 2008 8:58 pm
amit:
hei is so noce,.....
:: 4 :: Reply #97313 Reply By damien On Mon Mar 16, 2009 11:43 am
damien:
i am belgi this is very zero script
:: 5 :: Reply #97315 Reply By damien On Mon Mar 16, 2009 11:44 am
damien:
i am belgi this is very zero script
:: 6 :: Reply #113725 Reply By Jitendra On Tue Aug 25, 2009 2:46 am
Jitendra:
this script is very good .\r\nthis is very helffull and user friendly.\r\n\r\nthanks alote
:: 7 :: Reply #113727 Reply By Jitendra On Tue Aug 25, 2009 2:48 am
Jitendra:
this script is very good .\r\nthis is very helffull and user friendly.\r\n\r\nthanks alote
:: 8 :: Reply #113728 Reply By Jitendra On Tue Aug 25, 2009 2:48 am
Jitendra:
this script is very good .\r\nthis is very helffull and user friendly.\r\n\r\nthanks alote
:: 9 :: Reply #113729 Reply By Jitendra On Tue Aug 25, 2009 2:48 am
Jitendra:
this script is very good .\r\nthis is very helffull and user friendly.\r\n\r\nthanks alote
:: 10 :: Reply #119531 Reply By hemanth On Wed Nov 04, 2009 1:00 am
hemanth:
hi ,

the above code is working fine with all our requirements.

thanks
hema