function pagination($limit,$adjacents,$rows,$page){
$reqPage="";
if(isset($_REQUEST["page"])&& $_REQUEST["page"]!="")
$reqPage.="&page=".$_REQUEST["page"];
$pagination='';
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$prev_='';
$first='';
$lastpage = ceil($rows/$limit);
$next_='';
$last='';
if($lastpage > 1)
{
//previous button
if ($page > 1)
$prev_.= "<li><a class='page-numbers' href=\"?view=$prev$reqPage\">Previous</a></li>";
else{
//$pagination.= "<span class=\"disabled\">previous</span>";
}
//pages
if ($lastpage < 5 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
$first='';
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<li class=\"active\"><span>$counter</span></li>";
else
$pagination.= "<li><a class='page-numbers' href=\"?view=$counter$reqPage\">$counter</a></li>";
}
$last='';
}
elseif($lastpage > 3 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
$first='';
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<li class=\"active\"><span>$counter</span></li>";
else
$pagination.= "<li><a class='page-numbers' href=\"?view=$counter$reqPage\">$counter</a></li>";
}
$last.= "<li><a class='page-numbers' href=\"?view=$lastpage$reqPage\">Last</a></li>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$first.= "<li><a class='page-numbers' href=\"?view=1$reqPage\">First</a></li>";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<li class=\"active\"><span>$counter</span></li>";
else
$pagination.= "<li><a class='page-numbers' href=\"?view=$counter$reqPage\">$counter</a></li>";
}
$last.= "<li><a class='page-numbers' href=\"?view=$lastpage$reqPage\">Last</a></li>";
}
//close to end; only hide early pages
else
{
$first.= "<li><a class='page-numbers' href=\"?view=1$reqPage\">First</a></li>";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<li class=\"active\"><span>$counter</span></li>";
else
$pagination.= "<li><a class='page-numbers' href=\"?view=$counter$reqPage\">$counter</a></li>";
}
$last='';
}
}
if ($page < $counter - 1)
$next_.= "<li><a class='page-numbers' href=\"?view=$next$reqPage\">Next</a></li>";
else{
//$pagination.= "<span class=\"disabled\">next</span>";
}
$pagination = "<ul class=\"pagination pagination-sm\">".$first.$prev_.$pagination.$next_.$last;
//next button
$pagination.= "</ul>\n";
}
return $pagination;
}
$reqPage="";
if(isset($_REQUEST["page"])&& $_REQUEST["page"]!="")
$reqPage.="&page=".$_REQUEST["page"];
$pagination='';
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$prev_='';
$first='';
$lastpage = ceil($rows/$limit);
$next_='';
$last='';
if($lastpage > 1)
{
//previous button
if ($page > 1)
$prev_.= "<li><a class='page-numbers' href=\"?view=$prev$reqPage\">Previous</a></li>";
else{
//$pagination.= "<span class=\"disabled\">previous</span>";
}
//pages
if ($lastpage < 5 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
$first='';
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<li class=\"active\"><span>$counter</span></li>";
else
$pagination.= "<li><a class='page-numbers' href=\"?view=$counter$reqPage\">$counter</a></li>";
}
$last='';
}
elseif($lastpage > 3 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
$first='';
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<li class=\"active\"><span>$counter</span></li>";
else
$pagination.= "<li><a class='page-numbers' href=\"?view=$counter$reqPage\">$counter</a></li>";
}
$last.= "<li><a class='page-numbers' href=\"?view=$lastpage$reqPage\">Last</a></li>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$first.= "<li><a class='page-numbers' href=\"?view=1$reqPage\">First</a></li>";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<li class=\"active\"><span>$counter</span></li>";
else
$pagination.= "<li><a class='page-numbers' href=\"?view=$counter$reqPage\">$counter</a></li>";
}
$last.= "<li><a class='page-numbers' href=\"?view=$lastpage$reqPage\">Last</a></li>";
}
//close to end; only hide early pages
else
{
$first.= "<li><a class='page-numbers' href=\"?view=1$reqPage\">First</a></li>";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<li class=\"active\"><span>$counter</span></li>";
else
$pagination.= "<li><a class='page-numbers' href=\"?view=$counter$reqPage\">$counter</a></li>";
}
$last='';
}
}
if ($page < $counter - 1)
$next_.= "<li><a class='page-numbers' href=\"?view=$next$reqPage\">Next</a></li>";
else{
//$pagination.= "<span class=\"disabled\">next</span>";
}
$pagination = "<ul class=\"pagination pagination-sm\">".$first.$prev_.$pagination.$next_.$last;
//next button
$pagination.= "</ul>\n";
}
return $pagination;
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.