最好的分页方式[静态页带数字且从net到net_n开始]

本文介绍了一种使用ASP和VBScript实现动态网页分页的方法。通过创建动态HTML页面展示数据库中的记录,并提供了分页导航功能,允许用户浏览不同页的数据。文章详细展示了如何设置页面大小、生成HTML代码及实现翻页逻辑。

<!--#include file="function.asp"-->
<%set fso = Server.CreateObject("Scripting.FileSystemObject")
sql="select * from job"
rs.open sql,conn,1,3
rs.pagesize=10
if rs.pagecount=0 then
pagecounts=1
else
pagecounts=rs.pagecount
end if
pagecout=5     '定义数字每页显示个数
For Page = 1 To pagecounts
FileContent=""
    FileContent = FileContent & "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">" & vbCrLf
    FileContent = FileContent & "<html xmlns=""http://www.w3.org/1999/xhtml"">" & vbCrLf
    FileContent = FileContent & "<head>" & vbCrLf
    FileContent = FileContent & "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"" />" & vbCrLf
    FileContent = FileContent & "<meta http-equiv=""Content-Language"" content=""zh-cn"" />" & vbCrLf
    FileContent = FileContent & "<meta content=""all"" name=""robots"" /> " & vbCrLf
    FileContent = FileContent & "<meta name=""author"" content=""木目,Woodeye"" />" & vbCrLf
    FileContent = FileContent & "<link rel=""icon"" href=""/favicon.ico"" type=""image/x-icon"" />" & vbCrLf
    FileContent = FileContent & "<link rel=""shortcut icon"" href=""/favicon.ico"" type=""image/x-icon"" />" & vbCrLf
    FileContent = FileContent & "<link rel=""stylesheet"" rev=""stylesheet"" href=""../image/css.css"" type=""text/css"" media=""all"" />" & vbCrLf
    FileContent = FileContent & "<title>- 软件分类</title>" & vbCrLf
    FileContent = FileContent & "</head>" & vbCrLf

    FileContent = FileContent & "<body id=""body"">" & vbCrLf
  
    for k=1 to rs.pagesize
    If rs.Eof Then Exit For       '退出
  
    FileContent = FileContent & "<div id=""main"">" & vbCrLf
    FileContent = FileContent & "<span class=""soft_name""><a href='' target='_blank'><strong>" & rs("job_title") &" " & rs("job_company_name") & "</strong></a></span>" & vbCrLf
      FileContent = FileContent & "          <span class=""soft_time"">" & rs("job_addtime") & "</span>" & vbCrLf
  
    rs.movenext
    next
    FileContent = FileContent & "</div >" & vbCrLf
    FileContent = FileContent & "<div id=""main1"">" & vbCrLf
    FileContent = FileContent & "页次:"&page&"/"&rs.pagecount&" 每页"&rs.pagesize&" 电影数"&rs.recordcount&""
   
    if page<>1 then
     if page=2 then
        FileContent = FileContent & "<a href=net.htm> <font title=首页 face=webdings>9</font></a> <a href=net.htm> <font title=上一页 face=webdings>3</font></a>" & vbCrLf
     else
        FileContent = FileContent & "<a href=net.htm> <font title=首页 face=webdings>9</font></a> <a href=net_"&page-2&".htm> <font title=上一页 face=webdings>3</font></a>" & vbCrLf
     end if
    else
    FileContent = FileContent & "<font title=首页 face=webdings>9</font> <font title=上一页 face=webdings>3</font>" & vbCrLf
    end if
    '''生成数字分页开始
    pages=page
    if pages<=3 then     '判断当前页是否小于所设定的数字分页编号,如果是则使它从1开始计数
      pages=1
    end if
    if pages<=1 then    '判断当前页是否小于1
      pages=1
    end if
    if pages>rs.pagecount then     '判断当前页是否大于总的页数
pages=rs.pagecount
    end if
    if pagecout>rs.pagecount then      ''判断每页显示的数字数是否大于所有记录的总页数
pagecout=rs.pagecount
    end if
    mm=pages-2
    if pages<=3 then
      For y=1 to pagecout
     if cint(pages)=cint(y) then
          FileContent = FileContent & "<font color=""ff0000"">["&y&"]</font> " & vbCrLf
        else
      ' if pages=1 then
        'FileContent = FileContent & "[<a href=""net.htm"" title=""第"&y&"页"">"&y&"</a>] " & vbCrLf
     'mm=mm+1

    'else
     FileContent = FileContent & "[<a href=""net_" & Clng(y)-1 & ".htm"" title=""第"&y&"页"">"&y&"</a>] " & vbCrLf
     mm=mm+1
    'end if
     end if
Next
    else
      if pages>=rs.pagecount-1 then
     For x=rs.pagecount-pagecout+1 to rs.pagecount
       ' if pages=1 then
       '    FileContent = FileContent & "[<a href=""net.htm"" title=""第"&x&"页"">"&x&"</a>] " & vbCrLf
    ' else
      FileContent = FileContent & "[<a href=""net_" & Clng(x)-1 & ".htm"" title=""第"&x&"页"">"&x&"</a>] " & vbCrLf
     'end if
     Next
else
     For y=pages to pages+pagecout-1
       if mm=pages then
      FileContent = FileContent & "<font color=""ff0000"">["&mm&"]</font> " & vbCrLf
      mm=mm+1
    else
      if pages=1 then
          FileContent = FileContent & "[<a href=""net.htm"" title=""第"&mm&"页"">"&mm&"</a>] " & vbCrLf
       mm=mm+1
      else
    
       FileContent = FileContent & "[<a href=""net_" & Clng(mm)-1 & ".htm"" title=""第"&mm&"页"">"&mm&"</a>] " & vbCrLf
       mm=mm+1
    
      end if
    end if
     Next
    end if
     end if  
   
   
    '''生成数字分页结束
    if page<>rs.pagecount then
    FileContent = FileContent & "<a href=net_"&page&".htm> <font title=下一页 face=webdings>4</font></a> <a href=net_"&rs.pagecount-1&".htm> <font title=尾页 face=webdings>:</font></a>" & vbCrLf
else
    FileContent = FileContent & "<font title=下一页 face=webdings>4</font> <font title=尾页 face=webdings>:</font>" & vbCrLf
    end if
    ''生成跳转页
    FileContent = FileContent & "转到:" & vbCrLf
    FileContent = FileContent & "<select name=counts onChange=javascript:location=this.options[this.selectedIndex].value;>" & vbCrLf
    for kkk = 1 to rs.pagecount
       if kkk=1 then
    FileContent = FileContent & "<option value=net.htm selected=selected>第"&kkk&"页</option>" & vbCrLf
    else
      if kkk = page then
      FileContent = FileContent & "<option value=net_"&kkk&".htm selected=selected>第"&kkk&"页</option>" & vbCrLf
      else
      FileContent = FileContent & "<option value=net_"&kkk-1&".htm>第"&kkk&"页</option>" & vbCrLf
      end if
end if
    next
    FileContent = FileContent & "</select>" & vbCrLf
    ''生成跳转页结束
  
    FileContent = FileContent & "</div >" & vbCrLf
    FileContent = FileContent & "</body>" & vbCrLf
    FileContent = FileContent & "</html>" & vbCrLf
    if page=1 then
    GCFileName = "sort/net.htm"
    else
    GCFileName = "sort/net_" & Page-1 & ".htm"
    end if
    set fout = fso.CreateTextFile(server.mappath(""&GCFileName&""))
    fout.write FileContent
    set fout=nothing()
    ' rs.close()
next
%>
<a href="<%=GCFileName%>" target=_blank>查看文件</a>

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值