php分页代码(实用的分页程序)

  1. function pagenavi($total, $offset){
  2. global $conf_pagemax;
  3. global $conf_home;
  4. global $conf_pastlog;
  5. global $view;
  6. $next = $offset + $conf_pagemax;
  7. $prev = $offset - $conf_pagemax;
  8. echo " <!-- page navigation --> ";
  9. if($offset > $conf_pagemax-1){
  10. echo "<a href="index.php?offset=$prev";
  11. if($view == "past"){
  12. echo "&view=past";
  13. }
  14. echo ""><<上一页</a> ";
  15. }
  16. ($total % $pagemax)? $pagenum = ($total/$conf_pagemax) + 1: $pagenum = ($total/$conf_pagemax);
  17. if($total <= $conf_pagemax) $pagenum = 0;
  18. $c = 0;
  19. $page = 1;
  20. if($total > $conf_pagemax){
  21. echo "[<b> ";
  22. while($pagenum > 0){
  23. if($offset == $c){
  24. $str .= " $page ";
  25. } else {
  26. $str .= " <a href="index.php?offset=$c";
  27. if($view =="past"){
  28. $str .= "&view=past";
  29. }
  30. $str .= "">$page</a> ";
  31. }
  32. $page++;
  33. $pagenum--;
  34. $c = $c + $conf_pagemax;
  35. }
  36. echo "$str </b>] ";
  37. }
  38. if($next < $total){
  39. echo "<a href="index.php?offset=$next";
  40. if ($view == "past"){
  41. echo "&view=past";
  42. }
  43. echo "">下一页>></a> ";
  44. }
  45. echo "</td></tr></table>";
  46. echo " <!-- end of page navigation --> <br><br>";
  47. echo "
  48. [ <a href="$conf_home">返回主页</a> ]
  49. ";
  50. if($view != "past"){
  51. if(file($conf_pastlog)){
  52. echo "[ <a href="index.php?view=past">以前的留言</a> ]";
  53. }
  54. }
  55. echo " [ <a href="search.php"> 搜索</a> ] ";
  56. echo " [ <a href="index.php">留言板首页</a> ] ";
  57. }