分页的疑惑。解决了给分!

BrightEye 2002-05-29 03:27:29
我用ACCESS+ASP实现分页功能,程序结构是这样的.
login.htm中有个表单<input type=text name="querymonth">,通过POST方式提交到show.asp.
show.asp中根据用户输入的月份查询数据库记录,然后分页显示出来.显示格式是首页、上一页、下一页、末页。show.asp分页连接的代码如下:
<%
if Current_Page <> 1 then
%>
<A Href=show.asp?ToPage=1>第一页</A>
<A Href=show.asp?ToPage=<% = Current_Page - 1%>>上一页</A>
<%
end if
if Current_Page <> RS.PageCount then
%>
<A Href=show.asp?ToPage=<% = Current_Page + 1%>>下一页</A>
<A Href=show.asp?ToPage=<% = RS.PageCount%>>最后一页</A>
<%
end if
%>
点下一页时不能正常显示,哪儿有问题,请指教。谢了!!
...全文
28 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
BrightEye 2002-05-30
  • 打赏
  • 举报
回复
散分!
BrightEye 2002-05-29
  • 打赏
  • 举报
回复
基本搞定了,用session.
BrightEye 2002-05-29
  • 打赏
  • 举报
回复
谢谢!
qiyh1999 2002-05-29
  • 打赏
  • 举报
回复
我刚刚调通一个分页显示程序,你照着修改一下吧!<%="<p> <center> <font color=#FF00FF> <b>记录查询分页显示</b></font></center><p>"%>
<% Name = Request("Name")
PSize=10
Set conn = Server.CreateObject("ADODB.Connection")
Set rs=Server.CreateObject("ADODB.RecordSet")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("cuiq.mdb")
sql = "Select CuiqNo,Extract,Element,Dilute,Polar From Cuiq WHERE Extract='"&Name&"' Order By ID"
rs.open sql,Conn,3,1

if rs.RecordCount=0 then
response.write "<P> <center> Sorry, no data can be get!</center> </P>"
else
rs.PageSize=Cint(PSize)
PageN=Request("tempage")
if PageN="" then
PageN=1
end if
SA=Request("Coms")
if SA="上一页" then
PageN=PageN-1
elseif SA="下一页" then
PageN=PageN+1
elseif SA="确定" then
PageN=Request("p")
end if

rs.AbsolutePage=PageN
response.write "<center>"
pagebegin=rs.PageSize*(PageN-1)+1
if rs.PageSize*PageN<rs.RecordCount then
pageend=rs.PageSize*PageN
else
pageend=rs.RecordCount
end if

n=1
Total=rs.PageCount
response.write "<P> <font color=#FF00FF><b>数据库查询结果:</b>"
response.write "(共有"&rs.RecordCount&"条符合条件的信息,分"&Total&"页,显示第"&PageN&"页["&pagebegin&"-"&pageend&"])</font></P>"
%>
<form name="form1" method="get" action="single.asp">
<input type="hidden" name="tempage" value="<%=PageN%>">
<input type="hidden" name="Name" value="<%=name%>">

<%
if PageN>1 then
response.write "<input type=submit name='Coms'value='上一页'>"
end if
if PageN<>Total then
response.write "<input type=submit name='Coms'value='下一页'>"
end if
'response.write "<br>"
response.write "显示第<input type=text name='p' size=5>页"
response.write "<input type=submit name='Coms'value='确定'>"
response.write "</form>"
end if
%>
</form>
<%
response.write "<TABLE width=620 border=1 cellpadding=4 cellspacing=0 bgcolor=#FFFFFF>"
response.write "<tr bgcolor=#aabbff><font size=2><td><b>cuiqNo</b></td><td><b>Extract</b></td><td><b>Element</b></td><td><b>Dilute Agent</b></td><td><b>Polar phase</b></td><td><b>Details...</b></td></font><tr bgcolor=#ffffff>"
RC=rs.PageSize
Do While Not rs.EOF and RC>0
if n=1 then
response.write "<tr bgcolor=#ffffff>"
else
response.write "<tr bgcolor=#eeeeee>"
end if
n=1-n%>
<td> <%=rs("CuiqNo")%></td>
<td> <%=rs("Extract")%></td>
<td> <%=rs("Element")%></td>
<td> <%=rs("Dilute")%></td>
<td> <%=rs("Polar")%></td>
<td> <% Response.Write("<A HREF=display.asp?TABLE=")
Response.Write(rs("CuiqNo")+">")
Response.Write ("Whole Note")
Response.Write("</A>")%></td>
<% response.write"</tr>" %>
<% RC=RC-1
rs.MoveNext
Loop
Conn.Close
set rs=nothing
set Conn=nothing
%>
<% response.write" </table>" %>


BrightEye 2002-05-29
  • 打赏
  • 举报
回复
由于这个分页程序中设计到几个参数,我用session传递变量现在可以分页了,但每次查到的都是一个电话号码的费用明细,除非session变量过期.哪位高手知道如何解决?
BrightEye 2002-05-29
  • 打赏
  • 举报
回复
to ywz413(去留无意宠辱心惊) :
我是这么写的呀!.不行啊!到第二页的时候month成了空值.


ywz413 2002-05-29
  • 打赏
  • 举报
回复
完整的代码如下:
<%
month=request.querystring("month")
sql="...where month='"&month&"'"
...

if Current_Page <> 1 then
%>
<A Href=show.asp?ToPage=1>&month=<%=month%>>>第一页</A>
<A Href=show.asp?ToPage=<% = Current_Page - 1%>&month=<%=month%>>上一页</A>
<%
end if
if Current_Page <> RS.PageCount then
%>
<A Href=show.asp?ToPage=<% = Current_Page + 1%>>&month=<%=month%>>下一页</A>
<A Href=show.asp?ToPage=<% = RS.PageCount%>>&month=<%=month%>>最后一页</A>
<%
end if
%>
ywz413 2002-05-29
  • 打赏
  • 举报
回复
这样也是不对的,因为你问号后面带的是?month所以必须这么做month=<%=request.querystring("month")%>
你的querymonth不能在这里这么用。
keyterxian 2002-05-29
  • 打赏
  • 举报
回复

<%
end if
if Current_Page <> RS.PageCount then
%>
<A Href=show.asp?ToPage=<% = Current_Page + 1%>>下一页</A>
<A Href=show.asp?ToPage=<% = RS.PageCount%>>最后一页</A>
<%
end if
%>

改为:
<%
end if
if not Current_Page+1>RS.PageCount then
%>
<A Href=show.asp?ToPage=<% = Current_Page + 1%>>下一页</A>
<A Href=show.asp?ToPage=<% = RS.PageCount%>>最后一页</A>
<%
end if
%>

ywz413 2002-05-29
  • 打赏
  • 举报
回复
month=request.querystring("month")
应为是用? 来做的,所以只能用这种方式读取值
ywz413 2002-05-29
  • 打赏
  • 举报
回复
中根据用户输入的月份查询数据库记录
错误在这里,你在第一页的时候where ziduan='"&ziduandezhi&"'条件语句是有效的,可是在第二页的时候ziduandezhi已经丢失了所以第二页不能正常显示。你这么做<A Href=show.asp?ToPage=<% = Current_Page - 1%>&key=<%=key%>>这后面的KEY就是你查询条件里的ziduandezhi,然后你在下一页把这个值读取出来 就可以了
BrightEye 2002-05-29
  • 打赏
  • 举报
回复
我这么试了一下,给链接加个参数:
<A Href=show.asp?ToPage=<% = Current_Page - 1%>&month=<%request.form("querymonth")%>>上一页</A>
提取第二页记录时月份值传递不了,该如何解决.用session也解决不了.可能是.....
funboy88 2002-05-29
  • 打赏
  • 举报
回复
你要传月份,可是你的代码中没有传的呀,你不要想着,分页显示就是根据你第一页显示的记录数来分页
应该每一个连接是这样写:
<A Href=show.asp?ToPage=1&querymonth=<%=request("querymonth")%>>第一页</A>
funboy88 2002-05-29
  • 打赏
  • 举报
回复
可能就是楼上的错误,我遇到过几次同样的问题
BrightEye 2002-05-29
  • 打赏
  • 举报
回复
Current_Page有值,我是这么做的.问题是链接到自身有没有问题,为什么第二页的month(月份)参数传递不到下一页?
zyhowe 2002-05-29
  • 打赏
  • 举报
回复
Current_Page=cint(request("ToPage"))

28,391

社区成员

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

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