一个分页程序,到第二页的时候就会有数据重复,如何解决?

potter2002 2004-06-26 11:03:19
<%
sub move_prev(rs, num)
do while num > 0
rs.moveprevious
num = num - 1
loop
end sub
sub move_next(rs, num)
do while not rs.eof and num > 0
rs.movenext
num = num - 1
loop
end sub
'Variables declaration~
dim rs, sqlStr, newsPerPage, pageNo, pageTotal, i
'Build up the recordset~
set rs=server.CreateObject("adodb.recordset")
sql="select * from product where bigclass='1' order by id"
rs.open sql,conn,3,3

newsPerPage =5
if isempty(Request("page")) then
pageNo = 1
else
pageNo = Cint(Request("page"))
end if
if rs.recordcount = 0 then
pageTotal = 1
Response.Write("no")
else
if int(rs.recordcount / newsPerPage) = rs.recordcount / newsPerPage then
pageTotal = int(rs.recordcount / newsPerPage)
else
pageTotal = int(rs.recordcount / newsPerPage) + 1
end if

call move_next(rs, (pageNo - 1) * newsPerPage)
i = newsPerPage
do while not rs.eof and i>0
' j=1
%>
<tr>
<td><a href="trn.asp?id=<%=rs("id")%>"><img src="../pic/small/<%=rs("files2")%>" width=98 height=67 border=0></a></td>
<%rs.movenext%>
<td>
<%if not rs.eof then%>
<a href="trn.asp?id=<%=rs("id")%>"><img src="../pic/small/<%=rs("files2")%>" width=98 height=67 border=0></a></td>
<%
'j=j+1
' if j>1 then exit do
rs.movenext
end if
%>
</tr>
<%
i = i - 1

loop

rs.close
set rs=nothing
end if
%>
<tr>
<td colspan=2 align=center class=small>
<% 'if pageNo > 1 then %>
<div align="center"><img src="images/toleft.gif" width=8 height=8 border=0 hspace=8>
<%'end if
'if pageNo < pageTotal then
%>
<%
for i = 1 to pageTotal
Response.Write("<font color='#FF0000'><a href='?page=" & i & "'>" & i & "</a></font> ")
next
'end if
%><img src="images/toright.gif" width=8 height=8 border=0 hspace=8>
</div></td>
...全文
279 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
whb147 2004-06-26
  • 打赏
  • 举报
回复
下次,还有这种问题,找我,哈哈哈哈哈
potter2002 2004-06-26
  • 打赏
  • 举报
回复
<%
sub move_prev(rs, num)
do while num > 0
rs.moveprevious
num = num - 1
loop
end sub
sub move_next(rs, num)
do while not rs.eof and num > 0
rs.movenext
num = num - 1
loop
end sub
'Variables declaration~
dim rs, sqlStr, newsPerPage, pageNo, pageTotal, i
'Build up the recordset~
set rs=server.CreateObject("adodb.recordset")
sql="select * from product where bigclass='4' order by id"
rs.open sql,conn,3,3

newsPerPage =10
if isempty(Request("page")) then
pageNo = 1
else
pageNo = Cint(Request("page"))
end if
if rs.recordcount = 0 then
pageTotal = 1
Response.Write("no")
else
if int(rs.recordcount / newsPerPage) = rs.recordcount / newsPerPage then
pageTotal = int(rs.recordcount / newsPerPage)
else
pageTotal = int(rs.recordcount / newsPerPage) + 1
end if

call move_next(rs, (pageNo - 1) * newsPerPage)
i = newsPerPage
do while not rs.eof and i>0
%>
<tr>
<td><a href="trn.asp?id=<%=rs("id")%>"><img src="../pic/small/<%=rs("files2")%>" width=98 height=67 border=0></a></td>
<%
rs.movenext
i=i-1
%>
<td>
<%if not rs.eof then%>
<a href="trn.asp?id=<%=rs("id")%>"><img src="../pic/small/<%=rs("files2")%>" width=98 height=67 border=0></a></td>
<%rs.movenext%><%end if%>
</tr>
<%
i = i - 1
loop
rs.close
set rs=nothing
%>
<tr>
<td colspan=2 align=center class=small>
<% 'if pageNo > 1 then %>
<div align="center"><img src="images/toleft.gif" width=8 height=8 border=0 hspace=8>
<%'end if
'if pageNo < pageTotal then
%>
<%
for i = 1 to pageTotal
Response.Write("<font color='#FF0000'><a href='?page=" & i & "'>" & i & "</a></font> ")
next
'end if
%><img src="images/toright.gif" width=8 height=8 border=0 hspace=8>
<% end if %>
</div></td>
whb147 2004-06-26
  • 打赏
  • 举报
回复
i=i-1少用了一次
whb147 2004-06-26
  • 打赏
  • 举报
回复
你的2列写的不怎么不怎么好,呵呵
你用mod 2看看
potter2002 2004-06-26
  • 打赏
  • 举报
回复
我想要的结果是分两列输出的。
如果将我的程序改为一列也没有什么问题,
Jaron 2004-06-26
  • 打赏
  • 举报
回复
Function ExportPageInfo(ByRef PageCount, RecordCount, currentpage, PageSize, I, LinkFile)
Dim retval, J, pageNumber, BasePage
If currentpage = "" Then currentpage = 1 Else currentpage = CInt(currentpage)
retval = "第" & currentpage & "页/共" & PageCount & "页 "
retval = retval & "本页" & I & "条/共" & RecordCount & "条 "
If currentpage = 1 Then
retval = retval & "首页 前页 "
Else
retval = retval & "<a href='" & LinkFile & "page=1'>首页</a> <a href='" & LinkFile & "page=" & CStr(currentpage - 1) & "'>前页</a> "
End If
If currentpage = PageCount Then
retval = retval & "后页 末页"
Else
retval = retval & "<a href='" & LinkFile & "page=" & CStr(currentpage + 1) & "'>后页</a> <a href='" & LinkFile & "page=" & CStr(PageCount) & "'>末页</a>"
End If
retval = retval & " | "
BasePage = (currentpage \ 10) * 10
If BasePage > 0 Then retval = retval & " <a href='" & LinkFile & "page=" & (BasePage - 9) & "'><<</a>"
For J = 1 To 10
pageNumber = BasePage + J
If pageNumber > PageCount Then Exit For
If pageNumber = CInt(currentpage) Then
retval = retval & " <font color='#FF0000'>" & pageNumber & "</font>"
Else
retval = retval & " <a href='" & LinkFile & "page=" & pageNumber & "'>" & pageNumber & "</a>"
End If
Next
If PageCount < BasePage + 11 Then
retval = retval & " >>"
Else
If PageCount > BasePage Then retval = retval & " <a href='" & LinkFile & "page=" & (BasePage + 11) & "'>>></a>"
End If
ExportPageInfo = retval
End Function
muniu 2004-06-26
  • 打赏
  • 举报
回复
单独找一个分页的程序吧,有现成的好代码为什么不用?

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧