mysql 分页类

  1. /function fenyezhixin($table,$pagesize="",$paixu="",$do="",$wwhere=""){
  2. if(($table == "news_fabu") or ($table == "product_fabu") or ($table == "message") or ($table == "down_fabu") or ($table == "kucun")){
  3. $query = @mysql_query("select * from $table $wwhere");
  4. $pagesize = $pagesize;
  5. $sum = mysql_num_rows($query);
  6. if($sum == 0){
  7. $pagesize = 1;
  8. }
  9. if($pagesize=="0"){
  10. $sum = "1";
  11. }
  12. if (@($sum % $pagesize) == 0){
  13. $total = @(int)($sum / $pagesize);
  14. }else{
  15. $total = @(int)($sum / $pagesize) + 1;
  16. }
  17. if($total == 0){$total=1;}
  18. if (isset($_get['page'])){
  19. $p = (int)$_get['page'];
  20. }else{
  21. $p = 1;
  22. }
  23. $start = $pagesize * ($p - 1);
  24. $query = @mysql_query("select * from $table $wwhere order by $paixu limit $start,$pagesize") or die ("数据查询失败2!");
  25. if ($do == 1){
  26. $queryarray = array($query,$total,$sum,$p);
  27. return $queryarray;
  28. }
  29. if($do == 2){
  30. $parray = array($total,$sum,$p);
  31. return $parray;
  32. }
  33. }else{
  34. $query = @mysql_query("select * from $table $wwhere order by $paixu limit $pagesize") or die ("数据查询失败1!");
  35. if ($do == 1){
  36. $queryarray = array($query,$total,$sum,$p);
  37. return $queryarray;
  38. }
  39. if($do == 2){
  40. $parray = array($total,$sum,$p);
  41. return $parray;
  42. }
  43. }
  44. }
  45. //返回分页条
  46. function fenyedaohang($total="",$sum="",$p="",$menut=""){
  47. $w = substr($menut,strrpos($menut,"&")+1,2);
  48. $wr = substr($menut,strrpos($menut,"=")+1,strlen($menut));
  49. $pindao = $_server["script_name"];$pinstrlen = strrpos($pindao,"/"); $pindao = substr($pindao,$pinstrlen+1,strlen($pindao));
  50. if($w == "pr"){
  51. $queryr = mysql_query("select feiye.feiye_what from feiye where feiye.feiye_page = '$pindao'");
  52. $rows = mysql_fetch_row($queryr); $rrows = $rows[0];
  53. if(emptyempty($rrows)){
  54. mysql_query("insert into `feiye` (`feiye_page`, `feiye_what`) values ('$pindao', '$wr')");
  55. echo "<meta http-equiv='refresh' content='0'>";
  56. }else{
  57. if($wr != $rrows){
  58. mysql_query("update `feiye` set `feiye_what`='$wr' where (`feiye_page`='$pindao')");
  59. echo "<meta http-equiv='refresh' content='0'>";
  60. }
  61. }
  62. }
  63. if($w == "ne"){
  64. $queryr = mysql_query("select feiye.feiye_what from feiye where feiye.feiye_page = '$pindao'");
  65. $rows = mysql_fetch_row($queryr); $rrows = $rows[0];
  66. if(emptyempty($rrows)){
  67. mysql_query("insert into `feiye` (`feiye_page`, `feiye_what`) values ('$pindao', '$wr')");
  68. echo "<meta http-equiv='refresh' content='0'>";
  69. }else{
  70. if($wr != $rrows){
  71. mysql_query("update `feiye` set `feiye_what`='$wr' where (`feiye_page`='$pindao')");
  72. echo "<meta http-equiv='refresh' content='0'>";
  73. }
  74. }
  75. }
  76. echo "共"."$total"."页&nbsp;"."记录"."$sum"."条&nbsp;当前"."$p"."/"."$total"."页&nbsp;&nbsp;";
  77. if($total == 1){
  78. echo "<font class="page">首页</font>";
  79. }else{
  80. echo "<a href='?page=1&menu=$menut' class="page">首页</a>"."&nbsp;";
  81. }
  82. if ($p > 1){
  83. $prev = $p - 1;
  84. echo "<a href='?page=$prev&menu=$menut' class="page">上一页</a>"."&nbsp;";
  85. }else{
  86. echo "<font class="page">上一页</font>"."&nbsp;";
  87. }
  88. $page = $_get["page"];
  89. $pagesum = $page+5;
  90. if($total >= 11){
  91. if($pagesum <=11 ){
  92. $pagesum = 11;
  93. }
  94. }
  95. if($pagesum >= $total){
  96. $pagesum = $total;
  97. }
  98. $pagestart = $page - 5;
  99. if($pagestart <= 0){
  100. $pagestart = 1;
  101. }
  102. if($total >= 11 and ($total-4) <= $page){
  103. $pagestart = $total-10;
  104. }
  105. for($i=$pagestart;$i<=$pagesum;$i++){
  106. if($i == $p){
  107. echo "<font color=cccccc>&nbsp;$i&nbsp;</font>";
  108. }else{
  109. echo "<a href='?page=$i&menu=$menut' class="page" >$i</a>";
  110. }
  111. }
  112. if ($p < $total){
  113. $next = $p + 1;
  114. echo "&nbsp;<a href='?page=$next&menu=$menut' class="page" >下一页</a>"."&nbsp;";
  115. }else{
  116. echo "<font class="page" >下一页</font>"."&nbsp;";
  117. }//开源代码phpfensi.com
  118. if($total == 1){
  119. echo "<font class="page">尾页</font>";
  120. }else{
  121. echo "<a href='?page=$total&menu=$menut' class="page">尾页</a>";
  122. }
  123. }