<?
//----------------------------------分页函数共三个-------------------//
function setParam($param1) 
  { foreach( $param1 as $key) 
  {   global ${$key};
  $param .= urlencode($key).'='.urlencode(${$key}).'&';
  } 
  return $param;
 }    
function page1($sqlstr)//分页的第一个处理程序,用来处理一系列环境变量.
   {// ipsearch 2003-08-01 
//email [email protected]
 global $rows_num,$page,$pages_num,$per_page,$rows_offset,$per_screen;
 
    if (!isset($page)) $page=1;//第几页
 if (!isset($rows_offse)) $rows_offse=2; //每页起始偏移
    if (!isset($per_screen)) $per_screen=10;//分页样式2 3 显示的页数
 if (!isset($per_page)) $per_page=15;//每页记录行数。
 $query=mysql_query($sqlstr);
    $rows_num=mysql_num_rows($query); 
 $pages_num = ceil(($rows_num-$rows_offset)/$per_page);
 $str= $sqlstr." limit ".(($page-1)*$per_page+$rows_offset).", ".$per_page;
 return mysql_query($str);    
   }
function page2($style=2)
   {
    global $rows_num,$page,$pages_num,$per_page,$rows_offset,$param,$per_screen;
     $font_size="10pt";  
 
           
    switch($style) {
      case 2:
       /* 样式2:  共 记录 第一页 上一页 6 7 8 9 10 11 12 13 14 15 16 17 18 下一页 最后页 */
     $mid = ceil(($per_screen+1)/2); 
                 $nav = '';
                 if($page<=$mid ) {
      $begin = 1;
     }else if($page > $pages_num-$mid) {
      $begin = $pages_num-$per_screen+1;
     }else {
      $begin = $page-$mid+1;
     }
     if($begin<0) $begin = 1;
          if($page>1)   $nav .= "<a href='sell.php?$param&page=".($page-1)."' title='第".($page-1)."页'><span style='font-size=$font_size;'><img src='../images/page_left.gif' width='12' height='12' align='absmiddle' border='0'></span></a> ";
     $end = ($begin+$per_screen>$pages_num)?$pages_num+1:$begin+$per_screen;
     for($i=$begin; $i<$end; $i++) {
      $nav .=($page!=$i)?"<a href='sell.php?$param&page=$i' title='第{$i}页'><span style='font-size=$font_size;'>$i</span></a> ":"<span style='font-size=$font_size;color:red;'>$i</span> ";
     }
     if($page<$pages_num)   $nav .= "<a href='sell.php?
$param&page=".($page+1)."' title='第".($page+1)."页'><span style='font-size=$font_size;'><img src='../images/page_right.gif' width='12' height='12' align='absmiddle' border='0'></span></a>";    break;
    default:
     $nav = '';
   }  
  echo $nav;
   }// ipsearch 2003-08-01 
//email [email protected]
//--------------------------------------------------end 分页函数--------------?>
<? 
$str="select * from table"; 
$temp=page1($str);
$param1=array("id");
$param=setParam($param1);
while($result=mysql_fetch_array($temp)){  
?>
   
<tr>
  <td width="92%" align="left"><a href="">aaaaaaaaa</a></td>
</tr>
<? }?><tr>
  <td height="24" align="center" valign="middle">
    <?php page2(2);?>
  </td>
</tr>

解决方案 »

  1.   

    分页函数中有三个a href需要改动,上面的例子中是sell.php,你可以查找一下,然后替换成你需要分页的文件名即可!
      

  2.   

    错了!我是要SQL Server 2000的,不是MySQL的,MySQL的很简单的
      

  3.   

    如果要简单得分页的话,自己写个也不难。
    if(!isset($page))
    {$page=1;}
    $s=($page-1)*20//每页20条
    $sql="select * from table limit $s,20";
      

  4.   

    错了!我是要SQL Server 2000的,不是MySQL的,MySQL的很简单的
      

  5.   

    SQL Server 2000里面没有Limit
      

  6.   

    SQL Server 2000里面没有Limit--------------------------------
    但是有top
      

  7.   

    <?phpclass ShowPage
    {
    /**
     * 翻頁參數
     * @var string
     */
    var $pVar = "p";
    var $vPage = 8;//每页显示的下标,1、2、3、4、5、6、7、8
    /**
     * 當前頁
     * @var int
     */
    var $tPage;

    /**
     * 數據庫對象
     * @var conn
     */
    var $conn;

    /**
     * 數據庫表名
     * @var string
     */
    var $table;

    /**
     * 每頁顯示的數據條數
     * @var string
     */
    var $limit;

    /**
     * SQL語句
     * @var string
     */
    var $sqlQuery; /**
     * 構造函數
     * @param  conn $conn 數據庫對象,默認是pdo
     * @param  string $table 數據庫表名
     * @param  int $limit 每頁顯示的數據條數
     * @param  string $sqlQuery SQL語句(可選)where后面跟的查询参数 joyce
     * @todo  完成其他conn對象
     */
    function __construct($limit,$vpage,$pVar='p') {    
    $this->limit = $limit;//每页显示的记录数
    $this->pVar = $pVar;
    $this->vPage = $vpage;//当页可以切换的页数量
    }    function ShowStr(){
    if ($this->tPage > 0) {//总页数量,如273条记录,可以分为28页,每页10条。$this->tPage=28;$this->limit=10;$this->$vPage=8
    if($this->GetCurrentPage()<>1){//$this->GetCurrentPage()
    $forpage=$this->GetCurrentPage()-$this->vPage;
    if($forpage>=1){
    $str_start ="<a href=\"".$this->file.'?'.$this->pVar."=".$forpage."\">&lt;&lt;</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    }
    $start =  (ceil($this->GetCurrentPage()/$this->vPage)-1)*$this->vPage + 1;
    if($this->GetCurrentPage()<>$this->tPage){
    if($this->GetCurrentPage()<$this->tPage){
                     $forpage= ceil($this->GetCurrentPage()/$this->vPage)*$this->vPage +1;
     if($forpage<$this->tPage){
     $str_end .="<a href=\"".$this->file.'?'.$this->pVar."=".$forpage."\">&gt;&gt;</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    $end = $forpage;
     }else{
        $end = $this->tPage+1;
     }
            }else{
    $end = $this->tPage+1;
    }
     }else{
    $end = $this->tPage+1;
     }
    for ($i = $start; $i <$end; $i++) {
    if($i!=$this->GetCurrentPage()){
    $str_show .="<a href=\"".$this->file.'?'.$this->pVar."=".$i."\">".$i."</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    }else{
    $str_show .=$i."&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    }
        
    $str_show = $str_start . $str_show . $str_end;
    }
    else {
    $str_show = "";
    }
    return $str_show;
    } function UseDB($conn, $table, $sqlQuery = ""){
    $this->conn = $conn;
    $this->table = $table;
    $this->sqlQuery = $sqlQuery;
    $tmpQuery = "SELECT * FROM $this->table";
    if ($sqlQuery <> "") {
    $tmpQuery = $tmpQuery." WHERE ".$sqlQuery;//by joyce
    }
    //adoconn hack start
    $count = $conn->exec($tmpQuery) or die(print_r($conn->ErrorInfo()));
    $this->tPage = ceil($count / $this->limit);    // caculate the total page
    //$this->tPage = $count;
    }    /**
     * 設置翻頁參數
     * @param string $pvar  翻頁參數
     */
    function SetPageVar($pvar = 'p')  {    
            // set type turnpage parameter (E.G. http://www.aa.com/index.php?p=1)
    $this->pVar = $pvar;
    } /**
     * 返回總行數
     * @return  int
     */ function GetTotalRow() {
    return $this->tRow;
    }
        /**
     * 返回翻頁參數
     * @return string
     */
    function GetPageVar() {
    return $this->pVar;
    }
        /**
     * 返回當前頁數
     * @return int
     */
    function GetCurrentPage() {
    if($_GET[$this->pVar])
    return  $_GET[$this->pVar];
    else
    return 1;
    }
        /**
     * 返回總頁數
     * @return int
     */
    function GetTotalPage() {
    return $this->tPage;
    }    /**
     * 返回每頁顯示條數
     * @return int
     */
    function GetLimit() {   
    return $this->limit;
    } /**
     * 返回數據行數
     * @return  int
     */
    function GetRowFrom() {
    if ($this->GetCurrentPage() <= 1) {
    return 0;
    }
    else {
    return ($this->GetCurrentPage() - 1) * $this->GetLimit();
    }
    } /**
     * 設置其它參數
     * 設置翻頁時需要通過用GET方法一同傳送過去的其他參數
     * @param  array $data
     */
    function setVar($data) {    
    // set the turnpage addition value need to transfer by get mode
    foreach ($data as $k=>$v) {
    $this->varstr.='&'.$k.'='.urlencode($v);
    }
    }
    }
    ?>
      

  8.   

    为什么大家簿看清除题目呢???????
    我要的是SQL SERVER 2000的,不是要MySQL的!
      

  9.   

    为什么大家不看清除题目呢???????
    我要的是SQL SERVER 2000的,不是要MySQL的!
      

  10.   

    用一个SQL语句不就可以解决分页了:select * from table where state limit start,limit
    table:表名
    state:查询条件
    start:开始数
    limit:每页数量
      

  11.   

    昏,上面是连的SQLSERVER的,不要看到limit就以为是MYSQL,那只是个参数!
      

  12.   

    sql server里
    用top 结合 not in 即可
      

  13.   

    <?php
    //数据库连接模块
    $dbhost = "1";
    $dbuser = "2";
    $dbpwd = "3";
    $my_conn = mssql_connect($dbhost,$dbuser,$dbpwd);
    mssql_select_db('数据库名',$my_conn);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>php+mssql分页</title>
    </head>
    <?php

    //数据查询模块

    //服务器总数
    $count_chat_sql = "select count(gas_ip) as count from t_game_gas with (nolock)";
    $count_result   = mssql_query($count_chat_sql,$my_conn);
    $count_row      = mssql_fetch_array($count_result);
    $count          = $count_row['count']; //分页模块
    $pagex = $_GET['page']?$_GET['page']:1; //当前页面的页码
    $per_page = 20; //每页显示数量
    $pages      = ceil($count/$per_page);//总页数
    $forward    = $_GET['forward']?$_GET['forward']:0;
    $gas_ip = urlencode($_GET['offset']);

    //具体数量查询
    if ($forward == 0){
    $user_count_sql = "select top 20 gas_ip,sum(user_counts) as counts from t_game_gas with(nolock) group by gas_ip order by gas_ip";
    }else if ($forward == 1){
    $user_count_sql = "select top 20 gas_ip,sum(user_counts) as counts from t_game_gas with(nolock) where gas_id>$gas_ip group by gas_ip order by gas_ip";
    }else if ($forward == 2){
    $user_count_sql = "select * from ( select top 20 gas_ip,sum(user_counts) as counts from t_game_gas with(nolock) where gas_id<$gas_ip group by gas_ip order by gas_ip ) t order by t.gas_ip";
    }else {
    $user_count_sql = "select * from ( select top 20 gas_ip,sum(user_counts) as counts from t_game_gas with(nolock) group by gas_ip order by gas_ip ) t order by t.gas_ip";
    } $user_count_result = mssql_query($user_count_sql,$my_conn);
    while ($user_count_row = mssql_fetch_array($user_count_result))
    {
    $array_users[]=$user_count_row;
    }
    $size=count($array_users);
    $prev_offset = $array_users[0]['gas_ip'];//上翻页变量
    $next_offset = $array_users[$size-1]['gas_ip'];//下翻页变量
    ?>
    <table border="1" width="500">
    <tr>
    <td>IP</td>
    <td>Online User Counts</td>
    </tr>
    <?php
    for ($i=0;$i<=$size;$i++)
        if ($array_users[$i]['counts']<300)
        {
            echo "<tr class=\"highlight\"><td>".$array_users[$i]['gas_ip']."<td>".$array_users[$i]['counts']."</td></tr>";
        } elseif ($array_users[$i]['counts']>700) {
            echo "<tr class=\"green\"><td>".$array_users[$i]['gas_ip']."<td>".$array_users[$i]['counts']."</td></tr>";
        } else {
            echo "<tr><td>".$array_users[$i]['gas_ip']."<td>".$array_users[$i]['counts']."</td></tr>";
        }
    ?>
    </table><table border="1" cellspacing="0" cellpadding="3" width="500">
      <tr height=25>
        <td class=gb7>
    <?php echo "共有IP".$count."条记录 共有".$pages."页 当前第".$pagex."页 "; 
    if ($pagex==1)
    {
    echo "首页 上页 ";
    }else
    {
    echo "<a href=./index.php?forward=0&page=1>首页</a> ";
    echo "<a href=./index.php?forward=2&offset=$prev_offset&page=".($pagex-1).">上页</a> ";
    }
    if ($pagex>=$pages)
    {
    echo "下页 尾页";
    }else
    {
    echo "<a href=./index.php?forward=1&offset=$next_offset&page=".($pagex+1).">下页</a> ";
    echo "<a href=./index.php?forward=3&page=$pages>尾页</a> ";
    }
    ?>
        </td>
      </tr>
    </table>
    <body>
    </body>
    </html>
    这是我写的一个翻页例子
    没有写成类
    相应的表名和字段名做相应的替换就可以了
    很简单的翻页方式
      

  14.   

    这是我照网上说改的代码:
     <?php
                    require_once("includes/pager.php");  //引入pager.php
                    $pg = @$_REQUEST["pg"];  //接收当前的页码。
                    $pagelist = 10;  //设定每页显示10条记录
                    $limitFrom = 0; //开始limit的数,用于当前pg(即页码)小于2的场合。此时sql的语句为..... limit 0,10                if (!isset($pg))  //如果接收的页码为空,说明当前为第一页。
                    {
                    $pg = 1;    //把页码设定为第一页
                    }
                    if ($pg>1)  //当页码大于1 的时候,需要设定limitFrom。此时sql可能为 limit 30,10
                    {
                    $limitFrom  = $pagelist*($pg-1);    //这是个计算limitFrom小算法,仔细看看就能明白了。
                    }else{
                    $limitFrom = 0;
                    }                $connect = mysql_pconnect("localhost","root","hcedagb");
                    mysql_select_db("icbcoa",$connect);
                    //基本参数已经设置完成了,现在从数据库中取出总记录数
                    $sql = "select count(*) as total  from oa_rizhi where ((riqi>'".$mdate."') and (username='".$_SESSION["susername"]."'))";    //统计记录总数
                    $res = mysql_fetch_array(mysql_query($sql));
                    $countAll = $res['total'];                $sql = "select * from oa_rizhi where ((riqi>'".$mdate."') and (username='".$_SESSION["susername"]."')) order by riqi desc limit $limitFrom,$pagelist";
                    mysql_query("SET NAMES 'GBK'");
                    $result = mysql_query($sql);
                    //$data=mysql_fetch_array($result);
                    $rows = @mysql_num_rows($result);
                    while($data=mysql_fetch_assoc($result))
                    {
                     $riqi=$data['riqi'];
                     $neirong=$data['neirong'];
                     $sneirong = substr($neirong, 0,100);
                     $bianhao=$data['bianhao'];
                     //echo $bianhao;                ?>        <tr>                <td bgcolor="#C0C0C0"> <? echo $riqi; ?></td>
                    <td width="613" bgcolor="#FFFFFF"> <? echo $sneirong; ?></td>
                    <td width="61" bgcolor="#FFFFFF">&nbsp; <a href="rizhialt.php?bianhao=<?php echo($bianhao); ?>">修改</td>
            </tr>
             <?
                    }
                    mysql_close($connect);
             ?>
    </table>
       <tr><td><?php $pager = new Pager($countAll,$pagelist);?></td></tr>
      

  15.   

    怎么程序员都这样????
    为什么不看清除题目就乱贴代码啊????
    我再说不是要MySQL的分页!
    是要SQL SERVER 2000的!
      

  16.   

    怎么程序员都这样????
    为什么不看清除题目就乱贴代码啊????
    我再说不是要MySQL的分页!
    是要SQL SERVER 2000的!
      

  17.   

    结贴了,凡是没有看清问题给MySQL的,不给分了,呵呵