纪念一下当年用asp时 自己写的分页

  <%
  dim page,totalpage,pageitems   '当前页数,总共页数,显示条数
  pageitems=10
  page=request("page")
  '//////////////////////////////////////////////////////////////////////
   
  constr="driver={Microsoft Access Driver (*.mdb)};dbq="&server.MapPath("database/database.mdb")
  set conn=server.CreateObject("ADODB.Connection")
  conn.connectionstring=constr
  set rs=server.CreateObject("ADODB.Recordset")
  sql="select * from forum where parent=0 order by id desc"
  conn.open()
  rs.open sql,conn,1,1
  '//////////////////////////////////////////////////
  rs.PageSize=pageitems
  totalpage=cint(rs.RecordCount\pageitems)
 ' //////////////////////////////////////////////////
  if (rs.RecordCount mod pageitems)<>0 then
         totalpage=totalpage+1
  end if
 '///////////////////////////////////////////////////
 'response.Write(page)
 
  if  len(page)>0 and isnumeric(page) then
        rs.AbsolutePage=cint(page)
  else
        page=1
        rs.AbsolutePage=cint(page)
  end if
  num=1
  while not rs.eof and num<=pageitems
  %>
  <tr bgcolor="#FF99FF">
    <td>&nbsp;<%=num%></td>
    <td><span class="style5"><a href="forumdetails.asp?id=<%=rs("id")%>"><%=rs("subject")%></a></span></td>
    <td><span class="style5"><%select case cint(rs("face"))
                             case 1:%>
        <img src="mood/MOOD7.GIF" width="15" height="15">
        <% case 2:%>
         <img src="mood/MOOD8.GIF" width="15" height="15">
        <% case 3:%>
         <img src="mood/MOOD9.GIF" width="15" height="15">
        <% case 4:%>
         <img src="mood/MOOD0.GIF" width="15" height="15">
       <% end select %>
                          </span></td>
    <td><span class="style5"><%=rs("author")%></span></td>
    <td><span class="style5"><%=rs("sj")%></span></td>
    <td><span class="style5"><%rss=conn.execute("select count(*) from forum where parent="+cstr(rs("id")))
                            response.Write(rss(0))
                           %></span></td>
  </tr>
  <%
  num=num+1
  rs.movenext
  wend
  %>
</table>
<table width="90%"  border="0" align="center">
  <tr>
    <td align="right">
 <%if totalpage=1 then%>
   第<%=page%>页/
   共<%=totalpage%>页
 <% else
     temp=cint(page)
 select case temp
        case 1:%>
           <a href="forumshow.asp?page=<%=(page+1)%>">next</a>
   <%case totalpage :%>
            <a href="forumshow.asp?page=<%=(page-1)%>">prev</a>
     <%case else:%>   
           <a href="forumshow.asp?page=<%=(page-1)%>">prev</a>
 &nbsp;
           <a href="forumshow.asp?page=<%=(page+1)%>">next</a>
    <%end select
      end if%>
 <%i=cint(page)
   current=cint(page)
   j=0
     if totalpage>5 then
   if current-2>0 then
      if current+4>totalpage then
        i=totalpage-4
     response.Write("...")
        while i<=totalpage
        if i=current then
        response.Write("["+cstr(i)+"]")
        else
           response.Write("<a href="+"forumshow.asp?page="+cstr(i)+">"+"["+cstr(i)+"]</a>")
        end if
     i=i+1
        wend
    else
      response.Write("...")
      for i=current to current+4
      
           if i-2=current then
        response.Write("["+cstr(i-2)+"]")
        else
           response.Write("<a href="+"forumshow.asp?page="+cstr(i-2)+">"+"["+cstr(i-2)+"]</a>")
        end if
         next
      response.Write("...")
    end if 
   elseif current-2<=0 then  
     for i=1 to 5
      if i=current then
      response.Write("["+cstr(i)+"]")
      else
         response.Write("<a href="+"forumshow.asp?page="+cstr(i)+">"+"["+cstr(i)+"]</a>")
      end if
      next
        response.Write("...")
    end if   
  else
    for j=1 to totalpage
      if j=current then
   response.Write("["+cstr(j)+"]")
   else
      response.Write("<a href="+"forumshow.asp?page="+cstr(j)+">"+"["+cstr(j)+"]</a>")
   end if
    next
   end if
 %>
  第<%=page%>页/
 共<%=totalpage%>页
posted @ 2010-03-30 22:27  cyb  阅读(242)  评论(0编辑  收藏  举报