注册 登录
编程论坛 ASP技术论坛

ASP初学者:困扰今天的代码看不懂/那个高手帮我解释下

kivenonly 发布于 2009-11-10 22:32, 1039 次点击
Sub View_Words()
         dim gbcount,y,j,k
         set rs = conn.execute("select COUNT(*) as gbcount From words")
         gbcount=rs("gbcount")
         rs.close
         
         if gbcount/n = int(gbcount/n) then '计算出分页数
         y=int(gbcount/n)
         else
         y=int(gbcount/n)+1
         end if

         page2= int(page/x)
         if page/x>page2 then page2=page2+1
         k=page2*x
         if k>y then k=y

         '打开留言字段'
         if page=1 then
         sql="select top "&n&" id,name,sex,head,web,email,title,words,date,reply,ip,come,view,qq From words Order By id Desc"
         else
         sql="select id,name,sex,head,web,email,title,words,date,reply,ip,come,view,qq From words Order By id Desc"
         end if
         if Page >100 then
            rs.Open sql,Conn,1
         else
            Set Rs=Conn.Execute(sql)
         end if
         if Page>1 then RS.Move n*page-n
        %>
<table width="700" border="0" cellspacing="1" cellpadding="4" align="center">
          <tr>
            <td width="667" height="20" align="right" class="unnamed1">有<%=gbcount %>条留言  <%=page %>/<%=y %>页 分页
                <a href="?page=1"><<</a>
                <% if page2>1 then %>
                <a href="<%=indexfilename%>?page=<%=page2*x-x%>"><</a>
                <% end if %>
                <% For m =page2*x-(x-1) To k %>
      [<a href="<%=indexfilename%>?page=<%=m%>"><%=m%></a>]
      <%
    Next
    %>
      <% if page2*x < y then %>
      <a href="<%=indexfilename%>?page=<%=m%>">></a>
      <% end if %>
      <a href="?page=<%=y %>">>></a>
            </td>
          </tr>
5 回复
#2
yms1232009-11-15 18:06

Sub View_Words() '过程定义
         dim gbcount,y,j,k'变量定义
         set rs = conn.execute("select COUNT(*) as gbcount From words")'统计words标的记录数
         gbcount=rs("gbcount")'获得总记录数
         rs.close
         
         '一种分页算法
         if gbcount/n = int(gbcount/n) then '计算出分页数
         y=int(gbcount/n)
         else
         y=int(gbcount/n)+1
         end if

         page2= int(page/x)
         if page/x>page2 then page2=page2+1
         k=page2*x
         if k>y then k=y

         '打开留言字段'
         if page=1 then
         sql="select top "&n&" id,name,sex,head,web,email,title,words,date,reply,ip,come,view,qq From words Order By id Desc"
         else
         sql="select id,name,sex,head,web,email,title,words,date,reply,ip,come,view,qq From words Order By id Desc"
         end if
         if Page >100 then
            rs.Open sql,Conn,1
         else
            Set Rs=Conn.Execute(sql)
         end if
         if Page>1 then RS.Move n*page-n
        %>
<table width="700" border="0" cellspacing="1" cellpadding="4" align="center">
          <tr>
            <td width="667" height="20" align="right" class="unnamed1">有<%=gbcount %>条留言  <%=page %>/<%=y %>页 分页
                <a href="?page=1"><<</a>
                <% if page2>1 then %>
                <a href="<%=indexfilename%>?page=<%=page2*x-x%>"><</a>
                <% end if %>
                <% For m =page2*x-(x-1) To k %>
      [<a href="<%=indexfilename%>?page=<%=m%>"><%=m%></a>]
      <%
    Next
    %>
      <% if page2*x < y then %>
      <a href="<%=indexfilename%>?page=<%=m%>">></a>
      <% end if %>
      <a href="?page=<%=y %>">>></a>
            </td>
          </tr>
总的来说这段就是一段分页代码,但是在ASP里分页不用自己写算法的,这种写法很麻烦。
#3
chenguoxing5172009-11-15 23:58
就是分页的代码
#4
kivenonly2009-11-17 17:35
呵呵,谢谢各位大侠,就是自己对这个算法吸收不了
#5
gupiao1752009-11-18 22:02
读书百遍,其意自现,第一次不行,可以二次!
#6
makelee2009-11-19 13:25
是啊
1