Hi,
$num_rows should be changed so it gets the number of rows from database (like your own code)..
I havnt tested it very much, but if you create a new php-file and run that, you should be able to see how it works, before changing your own stuff.
PHP Code:
<?php
# Settings
$num_rows = 170; # How many rows in total
$rows_pr_page = 10; # How many rows per page?
$show_pages = 6; # How many page-links we want? (excluding current page)
$total_pages = ceil($num_rows/$rows_pr_page); # Calc number of pages
$current_page = intval(@$_GET['page']); # Get currnet page
# sanitize $current_page
if( $current_page < 1 ) $current_page = 1;
if( $current_page > $total_pages ) $current_page = $total_pages;
# Calc start page
$start_at_page = $current_page - floor($show_pages/2);
if( $start_at_page < 1 ) $start_at_page = 1;
# Calc end page
$end_at_page = $current_page + ceil($show_pages/2);
if( $end_at_page > $total_pages ) $end_at_page = $total_pages;
# Show "prev" link
if( $current_page > $start_at_page )
print page_link("[<<<]", $current_page - 1) . " ";
else
print page_link("[<<<]") . " ";
# Show page-links
for($page = $start_at_page; $page <= $end_at_page; $page++) {
$curpagelink = ($page == $current_page);
$link = "[$page]";
if( $curpagelink )
print page_link("<b>$link</b>") . " ";
else
print page_link($link, $page) . " ";
}
# Show "next" link
if( $current_page < $end_at_page )
print page_link("[>>>]", $current_page + 1) . " ";
else
print page_link("[>>>]") . " ";
# Helper function to creat ethe links
function page_link($text, $page=null) {
if( $page )
return "<a href=\"?page=$page\">$text</a>";
else
return $text;
}
?>
|