为什么这个翻页会自动翻到第一页?
我写了个站内查询,记录数为3页,初始值page设为1或或3都可以正确显示,但是点击“上一页”或“下一页”都自动翻到第一页,请高手帮助解决!!!
代码如下:(用一个表单调用此文件)<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<title>分页技术</title>
<head>
<%
const MaxPerPage=5
dim sql
dim rs
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
dim page
page=2
%>
</head>
<body bgcolor=Thistle>
<P align=center><FONT face=方正舒体><FONT size=5><STRONG>实例
分页技术</STRONG>
<%
word=trim(request("word"))
dim mycon,con
Set con=Server.CreateObject("ADODB.Connection")
mycon= "DRIVER=Microsoft Access Driver (*.mdb);DBQ="&Server.MapPath("/study/search.mdb")
con.open mycon
set rs=server.createobject("ADODB.Recordset")
rs.open "SELECT * FRoM redsearch where id or keyword or title like '%"&word&"%'",MyCon,1,3
if not(rs.eof and rs.bof) then
rs.movefirst
end if
rs.pagesize=MaxPerPage
howmanyfields=rs.Fields.Count-1
If trim(Request("word"))<>"" then
CurrentPage= page
If CurrentPage> rs.PageCount then
CurrentPage = rs.PageCount
End If
Else
CurrentPage= 1
End If
if rs.eof then
response.write "<p align='center'> ERROR!</p>"
else
totalPut=rs.recordcount
if CurrentPage<>1 then
if (currentPage-1)*MaxPerPage<totalPut then
rs.move(currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
end if
end if
dim n,k
if (totalPut mod MaxPerPage)=0 then
n= totalPut \ MaxPerPage
else
n= totalPut \ MaxPerPage + 1
end if%>
</FONT></FONT></P>
<P>PAGE <%=currentpage%> OF <%=n%> 共<%=rs.recordcount%> 条纪录
<% k=currentPage
if k<>1 then
response.write "[<b>"+"<a href='index.asp?page=1'>首页</a></b>] "
response.write "[<b>"+"<a href='index.asp?page="+cstr(k-1)+",word="+chr(34)+word+chr(34)+"''>上一页</a></b>] "
else
Response.Write "[首页] [上一页]"
end if
if k<>n then
response.write "[<b>"+"<a href='index.asp?page="+cstr(k+1)+",word="+chr(34)+word+chr(34)+"''>下一页</a></b>] "
response.write "[<b>"+"<a href='index.asp?page="+cstr(n)+",word="+chr(34)+word+chr(34)+"''>尾页</a></b>] "
else
Response.Write "[下一页] [尾页]"
end if
%>
</P>
<TABLE border=1 align=center>
<tr>
<%
for i= 0 to howmanyfields%>
<TD><B><%=rs(i).name%></B></TD>
<%
next
i=0
do while not rs.eof and i<maxperpage%>
<tr align=middle>
<%for j=0 to howmanyfields%>
<td>
<%=rs(j)%>
</td>
<%next%>
</tr>
<%
i=i+1
rs.movenext
loop
%>
</TABLE>
<%
end if
rs.close
set rs=nothing
%>
</body>
</html>
问题点数:50、回复次数:12Top
1 楼zyy1971(君子好学)回复于 2003-10-03 10:08:31 得分 0
各位,请在百忙中帮一下忙吧!!!!Top
2 楼lobu(享受编程)回复于 2003-10-03 10:24:27 得分 10
If cint(CurrentPage) > cint(rs.PageCount) then
cint(CurrentPage) = cint(rs.PageCount )
End IfTop
3 楼ping7963029(ping)回复于 2003-10-03 10:27:55 得分 0
你在回传页数时,出错了。重新检查一下页数回传是否有被处理模块接收。Top
4 楼avonqin(不再看连续剧)回复于 2003-10-03 11:12:28 得分 0
没见过对分页的处理这么乱的呀,其实十分简单的,你用这么多if then ,很容易出错的Top
5 楼zorou_fatal(The world and system is even)回复于 2003-10-03 11:17:40 得分 15
If trim(Request("word"))<>"" then
CurrentPage= page
If CurrentPage> rs.PageCount then
CurrentPage = rs.PageCount
End If
Else
CurrentPage= 1
End If
检查一下你的request("word")是不是空.Top
6 楼avonqin(不再看连续剧)回复于 2003-10-03 11:25:40 得分 0
<a href='index.asp?page="+cstr(k+1)+",word="+chr(34)+word+chr(34)+"''>下一页</a>
改为:
<a href='index.asp?page="+cstr(k+1)+"&word="+chr(34)+word+chr(34)+"''>下一页</a>
其它页码跳转也要改Top
7 楼avonqin(不再看连续剧)回复于 2003-10-03 11:28:27 得分 0
response.write "[<b><a href=index.asp?page="+cstr(k+1)+"&word="+chr(34)+word+chr(34)+">下一页</a></b>] "
Top
8 楼avonqin(不再看连续剧)回复于 2003-10-03 11:31:14 得分 0
错了,更正如下:
response.write "[<b><a href=index.asp?page="+cstr(k+1)+"&word="+word+">下一页</a></b>] "
Top
9 楼zyy1971(君子好学)回复于 2003-10-03 14:05:27 得分 0
可是还是没有反应啊!Top
10 楼minghui000(沉迷网络游戏)回复于 2003-10-03 14:20:57 得分 0
<a href='index.asp?page="+cstr(k+1)+",word="+chr(34)+word+chr(34)+"''>下一页</a>
改为:
<a href='index.asp?page="+cstr(k+1)+"&word="+chr(34)+word+chr(34)+"''>下一页</a>Top
11 楼zyy1971(君子好学)回复于 2003-10-03 16:59:09 得分 0
还是不行请,真让我着急, 不知问题出在哪儿?Top
12 楼avonqin(不再看连续剧)回复于 2003-10-04 01:12:25 得分 25
1、先改正上述我提出要修改的地方
2、
rs.open "SELECT * FRoM redsearch where id or keyword or title like '%"&word&"%'",MyCon,1,3
改为
rs.open "SELECT * FRoM redsearch where id like '%"&word&"%' or keyword like '%"&word&"%' or title like '%"&word&"%'",MyCon,1,1
Top




