如果我是第2頁(P = 2),這是尋呼機看怎麼樣 Första « 1 2 3 » Sista
但是,如果我第1或3看起來這分頁dupliacates第一頁和最後一頁頁上
(p = 1)1 2 3 3 » Sista
(p = 3)Första « 1 1 2 3
我在做什麼錯? 我正在使用來自本網站上發佈的另一個問題的邏輯,但沒有人像我一樣似乎遇到此問題。 Limit pagination page number
function get_paging_info($tot_rows,$pp,$curr_page)
{
$pages = ceil($tot_rows/$pp); // calc pages
$data = array(); // start out array
$data['si'] = ($curr_page * $pp) - $pp; // what row to start at
$data['pages'] = $pages; // add the pages
$data['curr_page'] = $curr_page; // Whats the current page
return $data; //return the paging data
}
function pagin($db,$sql,$limit,$curr_page,$max_pages=7)
{
$res = $db->query($sql);
$count = $res->num_rows;
$paging_info = get_paging_info($count,$limit,$curr_page);
$out[] = "
<nav aria-label='Page navigation'>
<ul class='pagination'>";
if($paging_info['curr_page'] > 1)
{
$out[] = "
<li><a href='?p=1' title='Sida 1'>Första</a></li>
<li>
<a href='?p=". ($paging_info['curr_page'] - 1) ."' aria-label='Föregående'>
<span aria-hidden='true'>«</span>
</a>
</li>";
}
$max = $max_pages;
if($paging_info['curr_page'] < $max)
{
$sp = 1;
}
elseif($paging_info['curr_page'] >= ($paging_info['pages'] - floor($max/2)))
{
$sp = $paging_info['pages'] - $max + 1;
}
elseif($paging_info['curr_page'] >= $max)
{
$sp = $paging_info['curr_page'] - floor($max/2);
}
if($paging_info['curr_page'] >= $max)
{
$out[] = "<li><a href='?p=1' title='Sida 1'>1</a></li>";
}
for($i = $sp; $i <= ($sp + $max -1);$i++)
{
if($i > $paging_info['pages']) continue;
if($paging_info['curr_page'] == $i)
{
$out[] = "<li class='active'><span class='strong'>". $i ."</span></li>";
}
else
{
$out[] = "<li><a href='?p=". $i ."' title='Sida ". $i ."'>". $i ."</a></li>";
}
}
if($paging_info['curr_page'] < ($paging_info['pages'] - floor($max/2)))
{
$out[] = "<li><a href='?p=". $paging_info['pages'] ."' title='Sida ". $paging_info['pages'] ."'>". $paging_info['pages'] ."</a></li>";
}
if($paging_info['curr_page'] < $paging_info['pages'])
{
$out[] = "
<li>
<a href='?p=". ($paging_info['curr_page'] + 1) ."' aria-label='Nästa' title='Page ". ($paging_info['curr_page'] + 1) ."'>
<span aria-hidden='true'>»</span>
</a>
</li>
<li><a href='?p=". $paging_info['pages'] ."' title='Sida ". $paging_info['pages'] ."'>Sista</a></li>";
}
$out[] = "</ul></nav>";
return implode('',$out);
}
謝謝!現在按預期工作 – Cirshiss