我想創建一個分頁,其中有5個項目一次取決於數據庫中的項目數。我寫了這段代碼。但我DONO如何去更好地buggy..any分頁或進一步改變。其本使用php與mysql數據分頁
<?php
$myresult .= "<div class='pagination' >";
if ($pagenum == 1)
{
}
else
{
$pagenum = 1;
$myresult .= "<a href='javascript:newPage(\"".$pagenum."\")'> first </a>";
$myresult .= " ";
$previous = $pagenum-1;
$myresult .= "<a href='javascript:newPage(\"".$previous."\")'> Prev </a>";
if ($pagenum == $last)
{
$previous3 = $pagenum-4;
$myresult .= "<a href='javascript:newPage(\"".$previous3."\")'> $previous3 </a>";
$previous2 = $pagenum-3;
$myresult .= "<a href='javascript:newPage(\"".$previous2."\")'> $previous2 </a>";
}
if ($pagenum > 2)
{
$previous1 = $pagenum-2;
$myresult .= "<a href='javascript:newPage(\"".$previous1."\")'> $previous1 </a>";
}
if ($pagenum > 1)
{
$previous2 = $pagenum-1;
$myresult .= "<a href='javascript:newPage(\"".$previous2."\")'> $previous2 </a>";
$myresult .= " ";
}
}
$myresult .= "<span class=\"disabled\"> $pagenum </span>";
if ($pagenum == $last)
{
}
else {
if($pagenum < $last - 1)
{
$next = $pagenum+1;
$myresult .= "<a href='javascript:newPage(\"".$next."\")'> $next </a>";
}
if($pagenum < $last - 2)
{
$next1 = $pagenum+2;
$myresult .= "<a href='javascript:newPage(\"".$next1."\")'> $next1 </a>";
}
if($pagenum == 1)
{
$next2 = $pagenum+3;
$myresult .= "<a href='javascript:newPage(\"".$next2."\")'> $next2 </a>";
$next3 = $pagenum+4;
$myresult .= "<a href='javascript:newPage(\"".$next3."\")'> $next3 </a>";
}
if($pagenum == 2)
{
$next2 = $pagenum+3;
$myresult .= "<a href='javascript:newPage(\"".$next2."\")'> $next2 </a>";
}
$next = $pagenum+1;
$myresult .= "<a href='javascript:newPage(\"".$next."\")'> Next </a>";
$myresult .= "<a href='javascript:newPage(\"".$last."\")'> Last</a>";
}
$myresult .= "</div>";
$myresult .= "</br>";
?>
分頁很大程度上取決於您打算實現的圖形方面! 你有圖片/截圖/無論你想創建什麼? 有了這個,我可以給你一個手... 關於你現在的代碼,你重複相同的語句分配,正如你所說,它是非常buggy :) – Zuul 2010-06-02 21:13:34
http://drupal.org/node ?page = 2我正在嘗試在底部創建類似分頁的內容。說分頁按鈕像第一,先導,3,4,5,6,7,下一個,最後。獲得第一,prev,next,last很容易,但中心5頁鏈接對我來說很困難 – Hacker 2010-06-03 05:06:40
我找到了解決方案。其在phpeasystep.com/phptu/29.html – Hacker 2010-06-03 06:29:31