I want to do in the following way, i would be very grateful if you help a little ...
Currently my way - from /first page / 1-7 ... 50/last page / 7 when i clicked appears in the following way photo 2, and i want when clicked on 7 appears to me as a photo 3
Photo 1
[img]http://img190.imageshack.us/img190/9590/pagesjs.jpg[/img]
The Оpposite
[img]http://img829.imageshack.us/img829/2821/pages4.jpg[/img]
Photo 2
[img]http://img192.imageshack.us/img192/4858/pages2t.jpg[/img]
Photo 3
[img]http://img85.imageshack.us/img85/5030/pages3.jpg[/img]
$tbl_name="users";
$adjacents = 3;
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
$targetpage = "users.php";
$limit = 15;
$page = $_GET['p'];
if($page)
$start = ($page - 1) * $limit;
else
$start = 0;
$sql = "SELECT * FROM $tbl_name ORDER by id DESC LIMIT $start, $limit";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {if ($page == 0) $page = 1;
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$lpm1 = $lastpage - 1;
$lastcounter = $lastpage -7;
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"navpage\">";
// Previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?p=$prev\">«</a>";
// Pages
if ($lastpage < 5 + ($adjacents * 2)) //not enough pages to bother him apart
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"navcurrent\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?p=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close enough to the beginning only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 2 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"navcurrent\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?p=$counter\">$counter</a>";
}
$pagination.= "<a href=\"$targetpage?p=$counter\" style='font-weight: bold; color: #666;'>...</a>";
$pagination.= "<a href=\"$targetpage?p=$lastpage\">$lastpage</a>";
}
//in the middle; hide some front and some back
elseif($lastpage - ($adjacents * 1) > $page && $page > ($adjacents * 1))
{
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"navcurrent\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?p=$counter\">$counter</a>";
} }
//near the end, just hide the top
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?p=$lastcounter\" style='font-weight: bold; color: #666;'>...</a>";
for ($counter = $lastpage - (0 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"navcurrent\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?p=$counter\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?p=$next\">»</a>";
$pagination.= "</div>\n";
}