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

ASP for循环分页问题

skybirdzw 发布于 2008-10-31 10:22, 2461 次点击
这是我用来循环生成分页的代码,现在的问题是生成的多个页面中内容部分是一样的!是不是RS在读取记录时出现了问题?我实在想不出来了! 请高手帮我看看这段代码?非常感激! 我在线等待~~

for page=1 to counts
    News_con=""
    Set rs=server.CreateObject("adodb.recordset")
    rs.open "select * from [product] where isMakeHtml=1 order by proid desc",conn,1,1
    rs.PageSize = num
    if Not IsEmpty(page) then
        if Not IsNumeric(page) then
        page=1
        else
        Page = cint(page)
        end if
        if Page > rs.PageCount then
        rs.AbsolutePage = rs.PageCount
        elseif Page <= 0 then
        rs.AbsolutePage = 1
        else
        rs.AbsolutePage = Page
        end if
    else
    rs.AbsolutePage=1
    end if
    Page = rs.AbsolutePage
    
    News_con=News_con & "<table border=0 cellpadding=0 cellspacing=0 width=730 align=center><tr>"
    For i = 1 to rs.PageSize
        News_con=News_con & "<td align=center><table border=0 width=335><tr><td align=left height=20 colspan=2><strong><a href='../"&rs("filepath")&"' target='_blank'>"&left(rs("title"),8)&"</a></strong></td></tr>"
        News_con=News_con & "<tr valign=top><td align=center><a href='"&rs("filepath")&"' target='_blank'><img src=../pictures/"&rs("smallimg")&" width=130 height=170 border=0></a></td><td style=word-break:break-all; width=205>"
        News_con=News_con & "<table border=0 width=205 class=cc><tr valign=top><td height=145>"
        if len(rs("content"))>80 then
        News_con=News_con &  left(rs("content"),80)&"..."   
        else  
        News_con=News_con & rs("content")  
        end if
        News_con=News_con &"</td></tr><tr><td align=right height=25><font id=detail><a href='../"&rs("filepath")&"' target='_blank'>详细内容>></a></font></td></tr></table></td></tr>"
        News_con=News_con & "<tr><td height=1 colspan=2 background=../images/tiao.jpg></td></tr></table>"
        News_con=News_con & "</td><td width=30>&nbsp;</td>"
    rs.MoveNext
        if rs.eof then exit for
        if i mod 2=0 then News_con=News_con & "</tr><tr><td height=8 colspan=6></td></tr><tr>"
    NEXT
    News_con=News_con & "</tr></table>"
    
    News_con=News_con&"<div align=center class=pageline>"
    If page=1 then
    News_con=News_con&"[<a Href=../Htmlfile/ProductList_"& 1 &".html>首页</a>]"
    News_con=News_con&"[<a Href=../Htmlfile/ProductList_"& 1 &".html>上一页</a>]"
    else
    News_con=News_con&"[<a Href=../Htmlfile/ProductList_"& 1 &".html>首页</a>]"
    News_con=News_con&"[<a Href=../Htmlfile/ProductList_"& page - 1 &".html>上一页</a>]"
    end if
    if page=rs.pagecount then
    News_con=News_con&"[<a Href=../Htmlfile/ProductList_"&rs.PageCount&".html>下一页</a>]"
    News_con=News_con&"[<a Href=../Htmlfile/ProductList_"&rs.PageCount&".html>尾页</a>]"
    else
    News_con=News_con&"[<a Href=../Htmlfile/ProductList_"&page + 1&".html>下一页</a>]"
    News_con=News_con&"[<a Href=../Htmlfile/ProductList_"&rs.PageCount&".html>尾页</a>]"
    end if
    News_con=News_con&"[页次:"&page&"/"&rs.PageCount&"]"
    News_con=News_con&"[共"&rs.RecordCount&"件产品 "&rs.PageSize&"件/页]"
    News_con=News_con&"</div>"
    rs.close
    Set rs = Nothing
    
    mb_code=replace(mb_code,"$leftmenu$",leftmenu)
    mb_code=replace(mb_code,"$content$",News_con)
    
    filename="../Htmlfile/ProductList_"&page&".html"'要生成的页
    Set files = fso.CreateTextFile(Server.MapPath(filename),true) '生成HTML页
    files.WriteLine mb_code '写入内容
    files.close
    set files=nothing
    'set fso=nothing
    
next
7 回复
#2
yms1232008-10-31 14:00
for page=1 to counts
这个循环什么意思?
#3
hmhz2008-10-31 15:14
哪有使用for来循环数据的,这样你的数据不是重复的嘛
#4
skybirdzw2008-10-31 17:30
counts就是rs.pagecount 值是2. 我改了一下,把这几行移动到FOR循环之外:

Set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [product] where isMakeHtml=1 order by proid desc",conn,1,1
rs.PageSize = num

hmhz说的就是这样的吧?
#5
multiple19022008-10-31 22:27
还有,循环内部为什么修改循环控制变量的值?
#6
skybirdzw2008-11-01 07:56
楼上说的是page吗? 这段放在FOR循环里应该没问题的吧?

if Not IsEmpty(page) then
        if Not IsNumeric(page) then
        page=1
        else
        Page = cint(page)
        end if
        if Page > rs.PageCount then
        rs.AbsolutePage = rs.PageCount
        elseif Page <= 0 then
        rs.AbsolutePage = 1
        else
        rs.AbsolutePage = Page
        end if
    else
    rs.AbsolutePage=1
    end if
    Page = rs.AbsolutePage

如果把这段移动到FOR循环外边就会出现page为空 啊! 可循环又必须得要page这个变量。
#7
shcms2008-11-03 14:15
大哥你写的分页代码真乱啊!!!!
给你写个简单的吧!
http://www.
1