pagination
pagination
<?php
$page = $_REQUEST['page'];
echo get_page_nav($page,20);
function get_page_nav($page_current, $page_total)
{
$ar_pages = array();
/* HTML-tag to select the current page */
$str_tag = 'strong';
/* Language strings */
$str_page_prev = 'previous';
$str_page_next = 'next';
/* String placed between the first and last page numbers */
$str_more = '..';
/* String to separate page numbers */
$str_d = ' - ';
/* URL for paging */
$str_url = 'index.php?page=%d';
/* The number of links to pages displayed before and after the current page. 1 2 (3) 1 2 */
$int_max = 2;
$cnt_new = $page_current;
$cnt_max = $page_current + $int_max;
$cnt_min = $page_current - $int_max;
/* Fix the maximum number of pages */
if ($cnt_max > $page_total)
{
$cnt_max = $page_total;
}
/* First page */
if ($cnt_min > 1)
{
$ar_pages[] = '<a href="'.sprintf($str_url, 1).'">1</a>';
$ar_pages[] = $str_more;
}
/* For each page number */
for ($i = 1; $i <= $page_total; $i++)
{
if ( ($i >= $cnt_min && $i <= $cnt_max) )
{
if ($i == $page_current)
{
$ar_pages[] = '<a href="'.sprintf($str_url, $i).'"><'.$str_tag.'>'.$i.'</'.$str_tag.'></a>';
}
else
{
$ar_pages[] = '<a href="'.sprintf($str_url, $i).'">'.$i.'</a>';
}
}
$cnt_new++;
}
/* The last page */
if ($cnt_max > 1 && ($page_current + $int_max) < $page_total)
{
$ar_pages[] = $str_more;
$ar_pages[] = '<a href="'.sprintf($str_url, $page_total).'">'.$page_total.'</a>';
}
/* Links to Next/Prev pages */
if ($page_current > 1)
{
$ar_pages[] = '<a href="'.sprintf($str_url, ($page_current - 1) ).'">'.$str_page_prev.'</a>';
}
if ($page_current < $page_total)
{
$ar_pages[] = '<a href="'.sprintf($str_url, ($page_current + 1) ).'">'.$str_page_next.'</a>';
}
return implode($str_d, $ar_pages);
}
?>
$page = $_REQUEST['page'];
echo get_page_nav($page,20);
function get_page_nav($page_current, $page_total)
{
$ar_pages = array();
/* HTML-tag to select the current page */
$str_tag = 'strong';
/* Language strings */
$str_page_prev = 'previous';
$str_page_next = 'next';
/* String placed between the first and last page numbers */
$str_more = '..';
/* String to separate page numbers */
$str_d = ' - ';
/* URL for paging */
$str_url = 'index.php?page=%d';
/* The number of links to pages displayed before and after the current page. 1 2 (3) 1 2 */
$int_max = 2;
$cnt_new = $page_current;
$cnt_max = $page_current + $int_max;
$cnt_min = $page_current - $int_max;
/* Fix the maximum number of pages */
if ($cnt_max > $page_total)
{
$cnt_max = $page_total;
}
/* First page */
if ($cnt_min > 1)
{
$ar_pages[] = '<a href="'.sprintf($str_url, 1).'">1</a>';
$ar_pages[] = $str_more;
}
/* For each page number */
for ($i = 1; $i <= $page_total; $i++)
{
if ( ($i >= $cnt_min && $i <= $cnt_max) )
{
if ($i == $page_current)
{
$ar_pages[] = '<a href="'.sprintf($str_url, $i).'"><'.$str_tag.'>'.$i.'</'.$str_tag.'></a>';
}
else
{
$ar_pages[] = '<a href="'.sprintf($str_url, $i).'">'.$i.'</a>';
}
}
$cnt_new++;
}
/* The last page */
if ($cnt_max > 1 && ($page_current + $int_max) < $page_total)
{
$ar_pages[] = $str_more;
$ar_pages[] = '<a href="'.sprintf($str_url, $page_total).'">'.$page_total.'</a>';
}
/* Links to Next/Prev pages */
if ($page_current > 1)
{
$ar_pages[] = '<a href="'.sprintf($str_url, ($page_current - 1) ).'">'.$str_page_prev.'</a>';
}
if ($page_current < $page_total)
{
$ar_pages[] = '<a href="'.sprintf($str_url, ($page_current + 1) ).'">'.$str_page_next.'</a>';
}
return implode($str_d, $ar_pages);
}
?>
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Fri Jul 22, 2011 1:37 pm by shyamsunder
» Thousands of Free PHP Scripts Recommended
Wed May 18, 2011 10:33 am by bizboy12
» PHP form validation problem?
Wed Jan 12, 2011 1:25 pm by simy202
» string wrap
Sat Aug 02, 2008 2:06 pm by scvinodkumar
» retrieving current date rows
Tue Jul 15, 2008 3:25 am by scvinodkumar
» number in words
Tue Apr 29, 2008 3:10 pm by scvinodkumar
» Simple PHP Form Field Generator
Fri Apr 25, 2008 12:28 pm by scvinodkumar
» PHP password generator
Fri Apr 18, 2008 7:24 pm by scvinodkumar
» PHP Script to Extract Email Address from any text
Fri Apr 18, 2008 7:18 pm by scvinodkumar