3种分页方法
1. 1 2 3 4 5
2. -1.html -2.html
3.动态 &page=1 &page=2
//取得分页 1 2
适用 .com/***/***/1
function PageList($iCurrentPage, $iPageCount, $QString = "", $Loop=10) { //echo $_SERVER['HTTP_HOST']; $tempString = "<p class='paging'>"; $iStart = 1; $iEnd = $iPageCount; if ($iPageCount > $Loop) { $iStart = (ceil ( $iCurrentPage / $Loop ) - 1) * $Loop + 1; $iEnd = (ceil ( $iCurrentPage / $Loop )) * $Loop; } if ($iEnd > $iPageCount) $iEnd = $iPageCount; if ($iCurrentPage == 1) { $tempString .= "<a class='unuse'>上一页</a>"; } else { $tempString .= "<a href='" . $QString ."1/'>首页</a>"; $tempString .= "<a href='" . $QString ."" . ($iCurrentPage - 1) . "/'>上一页</a>"; } //第一页,最后一页 for($i = $iStart; $i <= $iEnd; $i ++) { if ($i == $iCurrentPage) { $tempString .= "<a class='selected'>" . $i . "</a>"; } else { $tempString .= "<a href='" . $QString ."" . $i . "/'>" . $i . "</a>"; } } if ($iCurrentPage == $iPageCount) { $tempString .= "<a class='unuse'>下一页</a>"; } else { $tempString .= "<a href='" . $QString ."" . ($iCurrentPage + 1) . "/'>下一页</a>"; $tempString .= "<a href='" . $QString ."" . $iPageCount . "/'>末页</a>"; } $tempString .= "</p>"; if ($iPageCount == 0) $tempString = "<p class='paging'>无记录</p>"; return $tempString;}
//取得静态分页 -1 -2
适用于 -1.html -2.html 静态分页
function SplitPageList($iCurrentPage, $iPageCount, $QString = "", $Loop=10) { //echo $_SERVER['HTTP_HOST']; $tempString = "<p class='paging'>"; $iStart = 1; $iEnd = $iPageCount; if ($iPageCount > $Loop) { $iStart = (ceil ( $iCurrentPage / $Loop ) - 1) * $Loop + 1; $iEnd = (ceil ( $iCurrentPage / $Loop )) * $Loop; } if ($iEnd > $iPageCount) $iEnd = $iPageCount; if ($iCurrentPage == 1) { $tempString .= "<a class='unuse'>上一页</a>"; } else { $tempString .= "<a href='" . $QString ."-1.html'>首页</a>"; $tempString .= "<a href='" . $QString ."-" . ($iCurrentPage - 1) . ".html'>上一页</a>"; } //第一页,最后一页 for($i = $iStart; $i <= $iEnd; $i ++) { if ($i == $iCurrentPage) { $tempString .= "<a class='selected'>" . $i . "</a>"; } else { $tempString .= "<a href='" . $QString ."-" . $i . ".html'>" . $i . "</a>"; } } if ($iCurrentPage == $iPageCount) { $tempString .= "<a class='unuse'>下一页</a>"; } else { $tempString .= "<a href='" . $QString ."-" . ($iCurrentPage + 1) . ".html'>下一页</a>"; $tempString .= "<a href='" . $QString ."-" . $iPageCount . ".html'>末页</a>"; } $tempString .= "</p>"; if ($iPageCount == 0) $tempString = "<p class='paging'>无记录</p>"; return $tempString;}
适用于动态分页 &page=1
//取得分页
function SplitPageLite($iCurrentPage, $iPageCount, $QString = "", $Loop=10) { if ($QString == "" && isset ( $_SERVER ["QUERY_STRING"] )) $QString = "&" . preg_replace ( "/page=(\d*)&{0,1}/", "", $_SERVER ["QUERY_STRING"] ); $tempString = "<p class='paging'>"; $iStart = 1; $iEnd = $iPageCount; if ($iPageCount > $Loop) { $iStart = (ceil ( $iCurrentPage / $Loop ) - 1) * $Loop + 1; $iEnd = (ceil ( $iCurrentPage / $Loop )) * $Loop; } if ($iEnd > $iPageCount) $iEnd = $iPageCount; if ($iCurrentPage == 1) { $tempString .= "<a class='unuse'>上一页</a>"; } else { $tempString .= "<a href='" . $_SERVER ["PHP_SELF"] . "?page=1" . $QString . "'>首页</a>"; $tempString .= "<a href='" . $_SERVER ["PHP_SELF"] . "?page=" . ($iCurrentPage - 1) . $QString . "'>上一页</a>"; } //第一页,最后一页 for($i = $iStart; $i <= $iEnd; $i ++) { if ($i == $iCurrentPage) { $tempString .= "<a class='selected'>" . $i . "</a>"; } else { $tempString .= "<a href='" . $_SERVER ["PHP_SELF"] . "?page=" . $i . $QString . "'>" . $i . "</a>"; } } if ($iCurrentPage == $iPageCount) { $tempString .= "<a class='unuse'>下一页</a>"; } else { $tempString .= "<a href='" . $_SERVER ["PHP_SELF"] . "?page=" . ($iCurrentPage + 1) . $QString . "'>下一页</a>"; $tempString .= "<a href='" . $_SERVER ["PHP_SELF"] . "?page=" . $iPageCount . $QString . "'>末页</a>"; } $tempString .= "</p>"; if ($iPageCount == 0) $tempString = "<p class='paging'>无记录</p>"; return $tempString;}