pagination script how to create page numbers links function php
RegisterLogin
pagination script how to create page numbers links function php
Post Description: pagination script how to create page numbers links function php
Tags: pagination, script, how, to, create, page, numbers, links, function, php
This Post Was Posted On Dec 02, 2009 By web hosting #1301
Post Description: pagination script how to create page numbers links function php
Tags: pagination, script, how, to, create, page, numbers, links, function, php
This Post Was Posted On Dec 02, 2009 By web hosting #1301
pagination script how to create page numbers links function php by web hosting
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 = ' <a href="'.pagination_link($id, ($page_num -1 )).'">< PREV</a> ';
$first = '<a href="'.$_SERVER['PHP_SELF'].'">First Page <<</a>';
}
}
if($page_num <$total_pages){
$next = ' <a href="'.pagination_link($id, ($page_num+1)).'">NEXT ></a> ';
$last = ' <a href="'.pagination_link($id, $total_pages).'"> LAST PAGE >></a> ';
}
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 ' <strong>'.$page_counter.'</strong> ';
} else {
echo '<a href="'.pagination_link($id, ($page_counter)).'">'.$page_counter.'</a> ';
}
$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
Related Pages: [Add Your Website]
Post New Topic
©2011 Webune Forums - Wed Dec 21, 2011 4:58 am
Powered by: Webune Forums V3
Powered by: Webune Forums V3