你的和我是一样的问题,不过我用的是mssql,同是初学,关注一下

解决方案 »

  1.   

    我的不能翻页的代码:
    <?PHP
    extract($_GET);
    $conn=mssql_connect("localhost","sa","1" )  or die("Could not connect: " );
    mssql_Select_db("njc2",$conn);
    $strSQL="SELECT *  from rkgl";
    $result = mssql_query($strSQL);
    $total = mssql_num_rows($result);
    $pic= '<img src="images/real.gif">';
    $pagesize=10;
    if (($total%$pagesize)!=0) 
    $totalpage=intval($total/$pagesize)+1; 
    else 
    $totalpage=intval($total/$pagesize); 
    if ($page=="") 
    $current=1; 
    else{     
       switch($page){ 
        case "首页":  
        $current=1; 
        break; 
        case "上一页": 
        $current=$curpage-1; 
        break; 
        case "后一页": 
        $current=$curpage+1; 
        break; 
        case "尾页": 
        $current=$totalpage; 
        break;} 
        } 
        ?> 
        <b>第<?=$current;?>页,共<?=$totalpage;?>页.......共<?=$total;?>条记录  
     <?
    if($total<>0){ 
        mssql_data_seek($result,(($current-1)*$pagesize)); 

      } 
      $i=1; 
    ?>
    <table border="1" bgcolor="#F0FEE7" bordercolor="#336666"> 
    <? 
    while($row=mssql_fetch_row($result)) 
    {
    ?> 
          <tr> 
            <td><?=$row[0];?></td> 
            <td><?=$row[1];?></td> 
            <td><?=$row[2];?></td> 
            <td><?=$row[3];?></td> 
            <td><a href="play.php?id=<?=$row[0];?>"><?=$pic;?></a></td>
         </tr>
    <? 
        $i++; 
    if ($i>$pagesize) 
        break; 
    else 
        continue; 

    ?> 
    </table>
    <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?> "> 
      <input type="hidden" name="curpage" value="<?echo $current;?>"> 
      <input type="submit" name="page" value="首页"> 
     <? if($current>1):?> 
      <input type="submit" name="page" value="上一页"> 
      <? endif; 
      if($current<>$totalpage):?> 
      <input type="submit" name="page" value="后一页"> 
      <? endif;?> 
      <input type="submit" name="page" value="尾页"> 
    </form>
      

  2.   

    case "上一页": 
             $current=$curpage-1; 
             break; 
             case "后一页": 
             $current=$curpage+1; 
             break; 试试         case "上一页": 
             $current=$current-1; 
             break; 
             case "后一页": 
             $current=$current+1; 
             break;
      

  3.   

    case "上一页": 
             $current=$curpage-1; 
             break; 
             case "后一页": 
             $current=$curpage+1; 
             break; 试试         case "上一页": 
             $current=$current-1; 
             break; 
             case "后一页": 
             $current=$current+1; 
             break;
      

  4.   

    To littlejc2(半半):
    晕哦~我就是找帖,然后用你帖里的呀
    你也没解决?
      

  5.   

    To seabell(百合心):
    谢谢,不过还是不行.
      

  6.   

    呵呵,大家难兄难弟啊,这个程序肯定能用,好象是没有设置limit参数的问题。就是mssql不支持limit比较麻烦,你的mysql应该没有这个问题,看看老大们怎么解决的,私以为这个分页是很经典的一个分页程序
      

  7.   

    extract($_GET);   这里应该是取得点击后一页几个按钮后URL的值吧,比如前一页后一页首页尾页但是为什么没有变量名?
      

  8.   

    汗,居然原程序还有bug,谢谢seabell(百合心),不过还是翻不了页
      

  9.   


    这个源码里是不用limit的
    能实现limit的效果,每页显示相应的记录,但是不能翻!
      

  10.   

    那个东西应该没有什么用把。大家帮我们看看把,做成了这个就算懂点web编程了。
      

  11.   

    有用啊
    用来实现对当前页的控制我写ASP的...刚开始写PHP,晕,发觉PHP用起来真麻烦呀
    可能是习惯问题,呵呵
      

  12.   

    http://community.csdn.net/Expert/topic/3563/3563851.xml?temp=.2834894这个是我那个贴,马上下班了,可能要明天才能上线了,你弄好了,到我的贴里通知我一声怎么弄的啊,谢谢拉,以后一起学php,我也是从asp转过来的,其实觉得php很灵活的,比asp好点。
      

  13.   

    <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?> "> 
      <input type="hidden" name="curpage" value="<?echo $current;?>"> 
      <input type="submit" name="page" value="首页"> 
     <? if($current>1):?> 
      <input type="submit" name="page" value="上一页"> 
      <? endif; 
      if($current<>$totalpage):?> 
      <input type="submit" name="page" value="后一页"> 
      <? endif;?> 
      <input type="submit" name="page" value="尾页"> 
    </form>改成:
    echo "<a href=".$_SERVER['PHP_SELF']."?page=首页>首页</a> ";
      if ($current>1){
      echo "<a href=".$_SERVER['PHP_SELF']."?page=上一页>上一页</a> "; }
      if ($current!=$totalpage){
      echo "<a href=".$_SERVER['PHP_SELF']."?page=下一页>下一页</a> "; }
      echo "<a href=".$_SERVER['PHP_SELF']."?page=尾页>尾页</a> ";再在前面赋值:$page=$_GET['page'];可以实现首面,上一面,尾页的功能.但不能实现下一页的功能.........
    还有警告出现
    Warning: Offset -20 is invalid for MySQL result index 2
      

  14.   

    mssql_data_seek($result,(($current-1)*$pagesize)); 
    这行有错误!!!!
      

  15.   

    Warning: mssql_data_seek(): Bad row offset in C:\Program Files\Apache Group\Apache\htdocs\new2.php on line 45
      

  16.   

    To:littlejc2(半半)
    上面的的mssql_data_seek()是没有问题的。
    作用是用来指定N页后开始显示的第一条记录指针位置。PS:
    我结合原来的代码,自己写了一个。下面是代码,我已经测试成功。希望对你有所帮助。 :)mysql_connect("localhost","root","");
             $result=mysql_db_query("MsgBoard","select * from message");
             $total=mysql_num_rows($result);
     $pagesize=10;
             if (($total%$pagesize)!=0) 
             $totalpage=intval($total/$pagesize)+1; 
             else 
             $totalpage=intval($total/$pagesize); 
     if (empty($_GET['pagenum'])){
     $_GET['pagenum']=1; }
     if($total!=0){ 
               mysql_data_seek($result,(($_GET['pagenum']-1)*$pagesize)); 
                          } 
                     $i=1; 
       
       while($row=mysql_fetch_row($result)) 
       {
       echo "<tr>";
               echo "<td width=51%><div align=center>"."<a href=DisplayTopic.php?id=".$row["0"].">".$row["5"]."</a>"."</div></td>";
               echo "<td width=14%><div align=center>"."<a href=DisplayUserinfo.php?name=".$row["2"].">".$row["2"]."</a>"."</div></td>";
               echo "<td width=21%><div align=center>".$row["3"]."</div></td>";
               echo "<td width=14%><div align=center>"."<a href=DisplayUserinfo.php?name=".$row["2"].">".$row["6"]."</a>"."</div></td>";
               echo "</tr>";
      
     
      $i++; 
         if ($i>$pagesize) 
        break; 

         else 
          continue; 
             }
        ?>
        </table><br><?
      echo "<a href=".$_SERVER['PHP_SELF']."?pagenum=1>首页</a> ";
      if ($_GET['pagenum']>1){
      $temp_current=$_GET['pagenum']-1;
      echo "<a href=".$_SERVER['PHP_SELF']."?pagenum=".$temp_current.">上一页</a> "; }
      if ($_GET['pagenum']<$totalpage){
      $temp_current=$_GET['pagenum']+1;
      echo "<a href=".$_SERVER['PHP_SELF']."?pagenum=".$temp_current.">下一页</a> "; }
      echo "<a href=".$_SERVER['PHP_SELF']."?pagenum=".$totalpage.">尾页</a> ";
      

  17.   

    case "首页":  
             $current=1; 
             break; 
             case "上一页": 
             $current=$curpage-1; 
             break; 
             case "后一页": 
             $current=$curpage+1; 
    上面是你的程序,的一部分,你的页面的页数是通过$curpage变量来传递的,而$current并不会在页面之间传递值,所以你的页数的值是无法在各个页面之间传递的,当然也就只显示第一页了。