二款php mysql 分页代码

 代码如下 复制代码
function fenyezhixin($table,$pagesize="",$paixu="",$do="",$wwhere=""){
    if(($table == "news_fabu") or ($table == "product_fabu") or ($table == "message") or ($table == "down_fabu") or ($table == "kucun")){
    $query = @mysql_query("select * from $table $wwhere");
    $pagesize = $pagesize;
    $sum = mysql_num_rows($query);
    if($sum == 0){
        $pagesize = 1;
    }
 if($pagesize=="0"){
     $sum = "1";
 }
    if (@($sum % $pagesize) == 0){
     $total = @(int)($sum / $pagesize);
 }else{
     $total = @(int)($sum / $pagesize) + 1;
 }
    if($total == 0){$total=1;}
    if (isset($_get['page'])){
        $p = (int)$_get['page'];
    }else{
        $p = 1;
    }
    $start = $pagesize * ($p - 1);
    $query = @mysql_query("select * from $table $wwhere order by $paixu limit $start,$pagesize") or die ("数据查询失败2!");
    if ($do == 1){
        $queryarray = array($query,$total,$sum,$p);
        return $queryarray;
    }
    if($do == 2){
        $parray = array($total,$sum,$p);
        return $parray;
    }
 }else{
     $query = @mysql_query("select * from $table $wwhere order by $paixu limit $pagesize") or die ("数据查询失败1!");
     if ($do == 1){
            $queryarray = array($query,$total,$sum,$p);
            return $queryarray;
     }
     if($do == 2){
            $parray = array($total,$sum,$p);
            return $parray;
     }
 }
}
//返回分页条  
function fenyedaohang($total="",$sum="",$p="",$menut=""){
 $w = substr($menut,strrpos($menut,"&")+1,2);
 $wr = substr($menut,strrpos($menut,"=")+1,strlen($menut));
 $pindao = $_server["script_name"];$pinstrlen = strrpos($pindao,"/"); $pindao = substr($pindao,$pinstrlen+1,strlen($pindao));
    if($w == "pr"){
     $queryr = mysql_query("select feiye.feiye_what from feiye where feiye.feiye_page = '$pindao'");
  $rows = mysql_fetch_row($queryr); $rrows = $rows[0];
  if(empty($rrows)){
      mysql_query("insert into `feiye` (`feiye_page`, `feiye_what`) values ('$pindao', '$wr')");
   echo "<meta http-equiv='refresh' content='0'>";
  }else{
      if($wr != $rrows){
        mysql_query("update `feiye` set `feiye_what`='$wr' where (`feiye_page`='$pindao')");
     echo "<meta http-equiv='refresh' content='0'>";
   }
  }
 }
 if($w == "ne"){
     $queryr = mysql_query("select feiye.feiye_what from feiye where feiye.feiye_page = '$pindao'");
  $rows = mysql_fetch_row($queryr); $rrows = $rows[0];
  if(empty($rrows)){
      mysql_query("insert into `feiye` (`feiye_page`, `feiye_what`) values ('$pindao', '$wr')");
   echo "<meta http-equiv='refresh' content='0'>";
  }else{
      if($wr != $rrows){
        mysql_query("update `feiye` set `feiye_what`='$wr' where (`feiye_page`='$pindao')");
     echo "<meta http-equiv='refresh' content='0'>";
   } 
  }
 }
    echo "共"."$total"."页&nbsp;"."记录"."$sum"."条&nbsp;当前"."$p"."/"."$total"."页&nbsp;&nbsp;";
    if($total == 1){
        echo "<font  class="page">首页</font>";
    }else{
        echo "<a href='?page=1&menu=$menut' class="page">首页</a>"."&nbsp;";
    }
    if ($p > 1){
        $prev = $p - 1;
        echo "<a href='?page=$prev&menu=$menut' class="page">上一页</a>"."&nbsp;";
    }else{
        echo "<font class="page">上一页</font>"."&nbsp;";
    }
    $page = $_get["page"];
    $pagesum = $page+5;
    if($total >= 11){
        if($pagesum <=11 ){
            $pagesum = 11;
        }
    }
    if($pagesum >= $total){
        $pagesum = $total;
    }
    $pagestart = $page - 5;
    if($pagestart <= 0){
        $pagestart = 1;
    }
    if($total >= 11 and ($total-4) <= $page){
        $pagestart = $total-10;
    }
    for($i=$pagestart;$i<=$pagesum;$i++){
        if($i == $p){
            echo "<font color=cccccc>&nbsp;$i&nbsp;</font>";
        }else{
            echo "<a href='?page=$i&menu=$menut' class="page" >$i</a>";
        }
    }
    if ($p < $total){
        $next = $p + 1;
        echo "&nbsp;<a href='?page=$next&menu=$menut' class="page" >下一页</a>"."&nbsp;";
    }else{
        echo "<font class="page" >下一页</font>"."&nbsp;";
    }
    if($total == 1){
        echo "<font  class="page">尾页</font>";
    }else{
        echo "<a href='?page=$total&menu=$menut' class="page">尾页</a>";
    }
}
时间: 2024-08-26 09:19:19

二款php mysql 分页代码的相关文章

两款实用php分页代码

function outpege($ps教程,$page) { // $ps 累计信息数 $page 当前page数 $max 列表的最大数 $min 列表的最小值 $max      = ($page >= 5)? $page+5:10; if($max > $ps)$max =$ps; $min      =($page-5); if($min<1) $min =1; if($page>1)$pagelist = "<a href="?page=1&q

二款php无限分类代码与原理

第一分类(父分类)-->第二分类(子分类)-->第三分类(孙分类) 这种亲缘分类越多,程序和数据库教程的控制就越加的复杂困难.在同一级的分类处理和控制是非常的简单的,因为只需要一个数据库来记载这一级的分类就行了,如:系统,新闻等分类,在这一级上处理是很简单的,但对一个网站来说一级分类是不够的,还需要再分类 //我们建一个表"class" CREATE TABLE `class` (   `id` int(11) NOT NULL auto_increment COMMENT

php mysql 分页代码与分页原理详解

<? /*存放贴子的表结构------------------------------------------------------  代码如下 复制代码 create table bbsrow( bbsrow_id int(6) not null auto_increment, //贴子ID号 bbsrow_auth varchar(20) not null, //贴子作者 bbsrow_parentid int(6), //贴子的父亲贴子ID号,如为首发贴则为空 bbsrow_title

二款图片无缝滚动代码

<!--图片滚动代码开始--> <div id=demo style="background: #ffffff; overflow: hidden; width: 551px; color: #ffffff; height: 138px">         <table cellpadding=0 align=center border=0 cellspace="0">           <tr>          

二款js折叠菜单代码

<html> <head> <title>小巧的折叠菜单</title> <script language="网页特效"> <!-- begin var refer=true; function combo() { if (refer) {   document.all.contents.style.visibility="visible";   refer=false; } else {   doc

高效的MySQL分页代码

limit 10000,20的意思扫描满足条件的10020行,扔掉前面的10000行,返回最后的20行,问题就在这里,如果是limit 100000,100,需要扫描100100行,在一个高并发的应用里,每次查询需要扫描超过10w行,性能肯定大打折扣.文中还提到limit n性能是没问题的,因为只扫描n行. 首先看一下分页的基本原理: mysql教程> explain select * from message order by id desc limit 10000, 20g ********

php+mysql分页代码详解_php技巧

复制代码 代码如下: <?php    $perpagenum = 10;//定义每页显示几条    $total = mysql_fetch_array(mysql_query("select count(*) from a"));//查询数据库中一共有多少条数据    $Total = $total[0];                          //    $Totalpage = ceil($Total/$perpagenum);//上舍,取整    if(!i

简单实用php mysql分页代码

 代码如下 复制代码 $qh=mysql_query("select count(*) as rcnt from table where your_condition_here order by whatever"); $data=mysql_fetch_array($qh); $nr=$data["rcnt"]; //判断偏移量参数是否传递给了脚本,如果没有就使用默认值0 if (empty($offset)) { $offset=0; } //查询结果(这里是每

二款php分页实例代码

<style type="text/css教程"> 二款php教程分页实例代码 a.pagecool,.pagecoolselect,.pagecoolpre,.pagecoolnext,.pageinfo,.curtotalx,.pagecoolprex,.pagecoolnextx{float:left;height:20px;font-family:arial,宋体;color:#444;font-weight:bold} a.pagecool,.pagecoolse