<style type="text/css">
ul.pagination {
	font-family: "Arial", "Helvetica", sans-serif;
	font-size: 13px;
	height: 100%;
	list-style-type: none;
	margin: 10px 10px;
	overflow: hidden;
	padding: 0;
}
ul.pagination li.details {
	background-color: white;
	border-color: #C8D5E0;
	border-image: none;
	border-style: solid;
	border-width: 1px 1px 2px;
	color: #1E598E;
	font-weight: bold;
	padding: 3px 8px;
	text-decoration: none;
}
ul.pagination li.dot {
	padding: 3px 0;
}
ul.pagination li {
	float: left;
	list-style-type: none;
	margin: 0 3px 0 0;
}
ul.pagination li:first-child {
	margin-left: 0;
}

ul.pagination li a img {
	border: medium none;
}
ul.pagination li a.current {
	background-color: #FFF;
	padding: 3px 8px;
	border-radius:2px;
	-moz-border-radius:3px;
	color: #333333;
}
ul.pagination li a.current:hover {
	background-color: white;
}
ul.pagination li a:hover {
	background-color: #C8D5E0;
}
ul.pagination li a {
	background-color: #F6F6F6;
	border-color: #C8D5E0;
	border-image: none;
	border-style: solid;
	border-width: 1px 1px 2px;
	color: #1E598E;
	display: block;
	font-weight: bold;
	padding: 3px 8px;
	border-radius:2px;
	-moz-border-radius:3px;
	text-decoration: none;
}
</style>
<?php

 function pagination($per_page, $page, $url, $total){    
 
       	$adjacents = "2";
	
 
        $page = ($page == 0 ? 1 : $page); 
        $start = ($page - 1) * $per_page;                              
         
        $prev = $page - 1;                         
        $next = $page + 1;
        $lastpage = ceil($total/$per_page);
        $lpm1 = $lastpage - 1;
        $txt='#txt'; 
        $pagination = "";
        if($lastpage > 1)
        {  
            $pagination .= "<ul class='pagination'>";
                    $pagination .= "<li><a href='{$url}$prev$txt'>Previous</a></li>";
            if ($lastpage < 7 + ($adjacents * 2))
            {  
                for ($counter = 1; $counter <= $lastpage; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<li><a class='current'>$counter</a></li>";
                    else
                        $pagination.= "<li><a href='{$url}$counter$txt'>$counter</a></li>";                   
                }
            }
            elseif($lastpage > 5 + ($adjacents * 2))
            {
                if($page < 1 + ($adjacents * 2))    
                {
                    for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                    {
                        if ($counter == $page)
                            $pagination.= "<li><a class='current'>$counter</a></li>";
                        else
                            $pagination.= "<li><a href='{$url}$counter$txt'>$counter</a></li>";                   
                    }
                    $pagination.= "<li class='dot'>...</li>";
                    $pagination.= "<li><a href='{$url}$lpm1$txt'>$lpm1</a></li>";
                    $pagination.= "<li><a href='{$url}$lastpage$txt'>$lastpage</a></li>";     
                }
                elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
                {
                    $pagination.= "<li><a href='{$url}1'>1</a></li>";
                    $pagination.= "<li><a href='{$url}2'>2</a></li>";
                    $pagination.= "<li class='dot'>...</li>";
                    for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
                    {
                        if ($counter == $page)
                            $pagination.= "<li><a class='current'>$counter</a></li>";
                        else
                            $pagination.= "<li><a href='{$url}$counter$txt'>$counter</a></li>";                   
                    }
                    $pagination.= "<li class='dot'>..</li>";
                    $pagination.= "<li><a href='{$url}$lpm1$txt'>$lpm1</a></li>";
                    $pagination.= "<li><a href='{$url}$lastpage$txt'>$lastpage</a></li>";     
                }
                else
                {
                    $pagination.= "<li><a href='{$url}1'>1</a></li>";
                    $pagination.= "<li><a href='{$url}2'>2</a></li>";
                    $pagination.= "<li class='dot'>..</li>";
                    for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
                    {
                        if ($counter == $page)
                            $pagination.= "<li><a class='current'>$counter</a></li>";
                        else
                            $pagination.= "<li><a href='{$url}$counter$txt'>$counter</a></li>";                   
                    }
                }
            }
			
           
            if ($page < $counter - 1){
                $pagination.= "<li><a href='{$url}$next$txt'>Next</a></li>";
            }
            $pagination.= "</ul>\n";     
        }          
        return $pagination;
    } 		
		
?>
