我禁止發表評論。 我只想給你一個主意。 嘗試先檢查您的查詢,如果它提供了您想要檢索的正確數量的數據。
這是我最古老的分頁設計之一,很高興我保留它。
這是首頁:所有工作正常。
而這是最後一頁......正如你所看到的,沒有結果。
如果您的查詢很好,可能是您的START & LIMIT問題。
我用這個代碼,我從互聯網年前看到:(對不起,我刪除了原文評論)
$tbl_name="your_table";
$adjacents = 10; // (10*2)+1 = 21 pages between next and prev
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysqli_fetch_array(mysqli_query($query));
$total_pages = $total_pages[num];
$targetpage = "same_page.php";
$limit = 100; // rows to be displayed per page
$page = $_GET['page'];
if($page)
{
$start = ($page - 1) * $limit; // ** this caused the problem **
$start = ($page + $limit) - 1; // ** this fixed the problem **
}
else{
$start = 0;
}
$sql = "SELECT * FROM $tbl_name LIMIT $start, $limit ";
$result = mysqli_query($sql);
if ($page == 0) $page = 1;
$prev = $page - 1;
$Next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$lpm1 = $lastpage - 1;
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//Prev button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?search=$get&page=$prev\" >« Latest </a>";
else
$pagination.= "<span class=\"disabled\">« Latest </span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\"> $counter</span>";
else
$pagination.= "<a href=\"$targetpage?search=$get&page=$counter\" > $counter</a>"; // just ignore search=$get, I believe you don't need this
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?search=$get&page=$counter\" >$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?search=$get&page=$lpm1\" >$lpm1</a>";
$pagination.= "<a href=\"$targetpage?search=$get&page=$lastpage\" >$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?search=$get&page=1\" >1</a>";
$pagination.= "<a href=\"$targetpage?search=$get&page=2\" >2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?search=$get&page=$counter\" >$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?search=$get&page=$lpm1\" >$lpm1</a>";
$pagination.= "<a href=\"$targetpage?search=$get&page=$lastpage\" >$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?search=$get&page=1\" >1</a>";
$pagination.= "<a href=\"$targetpage?search=$get&page=2\" >2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?search=$get&page=$counter\" >$counter</a>";
}
}
}
//Next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?search=$get&page=$Next\" > Prev »</a>";
else
$pagination.= "<span class=\"disabled\"> Prev »</span>";
$pagination.= "</div>\n";
}
?>
/**
* YOUR TABLE
* GOES
* HERE
*/
<?php echo $pagination;?>
結果,最後一頁顯示正確的數據
我不擅長CI,但我希望這有助於。祝你好運!
我已經檢查了我的查詢,並沒有問題,所以我認爲我的錯在分頁邏輯@Jorz –
我可以有代碼嗎?謝謝 –
我更新了我的答案 – Jorz