先把将记录集取出,算出总件数,总页数,根据页面上传的值确定当前页应该是第几页,然后跳转。知道了每页件数和跳转页数很容易就算出了应该从第几条记录开始。注意不要超过最大件数就行了。
关于跳转,如果你是每次都重新检索的话,那直接这样就行了。如果不想每次都重新检索,那么你得把记录集放到session中。

解决方案 »

  1.   

    很好办,你先查出总共多少页,如果少于21,那么下拉表里有显示1-20,
    如果多于20,那就加上更多选项,<option value="21">更多</option>
    在设置一个hidden,<input type=hidden name="pagecount" value=页面总数(pagetcount)><div id=xx></div>
    当选择更多时:
    var str="<select name=\"mostpage\" onchange=\"chang()\">";
    for (i=21;i<pagecount,i++)
     {   str+="<option vlaue="+i+">第"+i+"页</option>"}
    str+="</select>
    xx.innerHtml=str;select里的change()和你前一个下拉表是同一个函数。
                      
      

  2.   

    同意zhpfaff(zhp)的方法,用系统提供的recordcount,pagesize等即可,给个asp的例子,base.asp中是数据库连接
    <%@language=vbscript%>
    <%option explicit%>
    <!--#include file="base.asp"-->
      <table width="777" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#E4EDF8" class="kmwin">
      <tr>
        <td align="right" height="43">
          <table align=center border=0 cellspacing=1 width="95%" cellpadding=1 bgcolor="#000000" class="kmwin">
            <tbody> 
            <tr align="center"> 
              <td bgcolor=#9898ba 
              width=32% class=kmwin height="32" 
              ><b><font color="#FFFFFF">主 题</font></b></td>
              <td bgcolor=#9898ba 
              width=20% class=kmwin 
              ><b><font color="#FFFFFF">主题发起人</font></b></td>
              <td bgcolor=#9898ba 
              width=8% class=kmwin 
              ><b><font color="#FFFFFF">回 复</font></b></td>
              <td class=kmwin 
              bgcolor=#9898ba width="40%"><b><font color="#FFFFFF">最后发表</font></b></td>
            </tr>
    <%
    dim rs,sql
    set rs=nothing
    set rs=server.createobject("adodb.recordset")
    sql="select * from bbsinfo where topic="&cint(request("topic"))&" and father=1 and op=0 order by lasttime Desc"
    rs.open sql,conn,1,3
    if rs.eof and rs.bof then
    else
    if rs.recordcount<=30 then
    while not rs.eof
    if session("userlv")>=rs("lv") then
    %>
    <tr>
    <td align=middle bgcolor=#f0f3fa class=d1><a href="show.asp?uid=<%=rs("id")%>&topic=<%=request("topic")%>&mc=<%=request("mc")%>&father=<%=request("father")%>" title=<%=rs("title")%>><%=rs("title")%></a></td>
    <td align=middle bgcolor=#f0f3fa class=d1><%=rs("writer")%></td>
    <td align=middle bgcolor=#f0f3fa class=d1><% if rs("huifu")>=10 then%>
    <font color=red><%=rs("huifu")%></font>
    <%else%>
    <%=rs("huifu")%>
    <%end if%></td>
    <td align=middle bgcolor=#f0f3fa class=d1><%=rs("lasttime")%></td>
    </tr>
    <%
    end if
    rs.movenext
    wend
    else
    dim nowpage,i
    rs.pagesize=30
    if request("page")="" then
    nowpage=1
    else
    if cint(request("page"))<0 or Cint(request("page"))>rs.pagecount then
    nowpage=1
    else
    nowpage=cint(request("page"))
    end if
    end if
    rs.absolutepage=nowpage
    for i=1 to rs.pagesize
    %>
    <tr>
    <td align=middle bgcolor=#f0f3fa class=d1><a href="show.asp?uid=<%=rs("id")%>&topic=<%=request("topic")%>&mc=<%=request("mc")%>&father=<%=request("father")%>" title=<%=rs("title")%>><%=rs("title")%></a></td>
    <td align=middle bgcolor=#f0f3fa class=d1><%=rs("writer")%></td>
    <td align=middle bgcolor=#f0f3fa class=d1><% if rs("huifu")>=10 then%>
    <font color=red><%=rs("huifu")%></font>
    <%else%>
    <%=rs("huifu")%>
    <%end if%></td>
    <td align=middle bgcolor=#f0f3fa class=d1><%=rs("lasttime")%></td>
    </tr>
    <%
    rs.movenext
    if rs.eof then
    i=i+1
    exit for
    end if
    next
    %>
    <table border=0 cellspacing=1 cellpadding=1 width=80% align=center>
    <tr>
    <td class=d1><%if nowpage=1 then
    response.write "首页"
    else
    response.write "<a href=listshow.asp?page=1&topic="+request("topic")+"&mc="+request("mc")+"&father="+request("father")+">首页</a>"
    end if
    %>
    </td>
    <td class=d1><%if nowpage=1 then
    response.write "上一页"
    else
    response.write "<a href=listshow.asp?page="+cstr(nowpage-1)+"&topic="+request("topic")+"&mc="+request("mc")+"&father="+request("father")+">上一页</a>"
    end if
    %>
    </td>
    <td class=d1><%if nowpage=rs.pagecount then
    response.write "下一页"
    else
    response.write "<a href=listshow.asp?page="+cstr(nowpage+1)+"&topic="+request("topic")+"&mc="+request("mc")+"&father="+request("father")+">下一页</a>"
    end if
    %>
    </td>
    <td class=d1><%if nowpage=rs.pagecount then
    response.write "末页"
    else
    response.write "<a href=listshow.asp?page="+cstr(rs.pagecount)+"&topic="+request("topic")+"&mc="+request("mc")+"&father="+request("father")+">末页</a>"
    end if
    %>
    </td>
    <td class=d1>
    共有<%=rs.recordcount%>篇文章&nbsp;&nbsp;&nbsp;&nbsp;<%=nowpage%>/<%=rs.pagecount%>页
    </td>
    </tr>
    </table>
    <%
    end if
    end if
    %>
            </tbody> 
          </table>
          <br>
        </td>
      </tr>
    </table>
      

  3.   


    <?
    $db_name="xxxx";
    require("con_db.inc");
    $type=$HTTP_GET_VARS[type];
    $query="select * from girls where type=$type order by uptime desc";
    $result=mysql_query($query);
    $total=mysql_num_rows($result);$eachpage=10;
    if(!($page))$page=0;
    $start=$page*$eachpage;
    $end=$start+$eachpage;
    if($end>$total) {$end=$total;}
    $totalpage=$total/$eachpage;$pagestr="共有".$total."篇文章 ";
    if($page>0) $pagestr=$pagestr."[<a href=".$PATH_INFO."?type=$type&page=".($page-1).">上一页</a>]";
    $pagestr=$pagestr."[第";
      for ($i=0;$i<$totalpage;$i++){
         if ($i!=$page) {$pagestr=$pagestr."<a href=".$PATH_INFO."?type=$type&page=".$i.">".($i+1)."</a> ";}
         else {$pagestr=$pagestr.($i+1)." ";}
       }
    $pagestr=$pagestr."页]";
    if($page<($totalpage-1)){$pagestr=$pagestr." [<a href=".$PATH_INFO."?type=$type&action=view&page=".($page+1).">下一页</a>]";}for ($i=$start; $i<$end; $i++) {
      $show[$i][id]=mysql_result($result,$i,"id");
      $show[$i][title]=mysql_result($result,$i,"title");
      $show[$i][click]=mysql_result($result,$i,"click");     
      $show[$i][uptime]=mysql_result($result,$i,"uptime");     
      $show[$i][content]=mysql_result($result,$i,"content");
      $show[$i][imageid]=mysql_result($result,$i,"imageid");
      $id=$show[$i][id];
      $title=$show[$i][title];
      $titleall=$title;
      $leng=strlen($title);
      if($leng>36){$leng=36; $title=substr($title,0,$leng)."...";}
      $click=$show[$i][click];
      $uptime=substr($show[$i][uptime],0,10);
      $content=$show[$i][content];
      $imageid=$show[$i][imageid];
    echo "<table width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" class=\"title\">";
    echo "  <tr>";
    echo "  <td width=\"5%\"><img src=\"images/tag.gif\" width=\"14\" height=\"10\"></td>";
    echo "  <td width=\"60%\"><a href=\"../php/content.php?id=$id\" class=\"titlelink\" target=\"_blank\" title=\"$titleall\">$title</a></td>";
    echo "  <td width=\"20%\" class=\"datept\">$uptime</td>";
    echo "  <td width=\"15%\" align=\"right\"><font class=\"datept\">点击:</font><font class=\"click\">$click</font><font class=\"datept\">次</font></td>";
    if($level==admin){
    echo "  <td><a href=\"JavaScript:del($id,$imageid);\" class=\"datept\">删除</a></td>";}
    echo "  </tr>";
    echo "</table>";
    }
    echo "<table width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" class=\"buttom\">";
    echo "  <tr>";
    echo "  <td align=\"right\" class=\"datept\">$pagestr</td>";
    echo "  </tr>";
    echo "</table>";
    ?>