ASP分页难题求解 ,搜索结果点"下一页"却显示全部记录???详细给高分>>

liu_ff123 2007-03-24 02:24:39

<%


keys=request.form("key")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("phone.mdb")
exec="select * from bill where phone like '%"&keys&"%' or phone2 like '%"&keys&"%'"
set rs=server.CreateObject("adodb.recordset")
rs.open exec,conn,1,1
set rs1=server.CreateObject("adodb.recordset")
sql="SELECT sum(Bill.charge) as www FROM Bill WHERE phone like '%"&keys&"%'"

rs1.open sql,conn,1,1


rs.pagesize=20
zongye=rs.pagecount
page=int(request("page"))
if page<=0 then page=1
if request("page")="" then page=1
rs.absolutepage=page


%>
<html>
<head>
<title>话费查询</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="20" bottommargin="0">

<table border="0" width="100%" id="table1" bgcolor="#D5EAFD">
<tr>
<td width="167">您查询的分机号码是:</td>
<td width="276"> <%response.write(keys) %></td>
<td width="90">话费总计:</td>
<td><%= rs1("www") %> </td>
</tr>
</table>

<table width="100%" border="1" cellpadding="0" cellspacing="0">
<p> 
<tr>
<td width="10%" height="31" bgcolor="#F7F7F7">拨打日期</td>
<td width="10%" height="31" bgcolor="#F7F7F7">拨打时间</td>
<td width="10%" height="31" bgcolor="#F7F7F7">通话时长</td>
<td width="10%" height="31" bgcolor="#F7F7F7">通话费用</td>
<td width="10%" height="31" bgcolor="#F7F7F7">拨打类型</td>
<td width="10%" height="31" bgcolor="#F7F7F7">机主姓名</td>
<td height="31" bgcolor="#F7F7F7">部门</td>
</tr>



<%
if rs.eof or rs.bof then
response.write("没有找到记录!")
else



for i=1 to rs.pagesize
%>


</p>
<tr>
<td width="10%"><%=rs("startdate")%></td>
<td width="10%"><%=rs("starttime")%></td>
<td width="10%"><%=rs("duration")%></td>
<td width="10%"><%=rs("charge")%></td>
<td width="15%"><%=rs("destination")%></td>
<td width="10%"><%=rs("username")%></td>
<td><%=rs("department")%></td>
</tr>



<%
rs.movenext
next
end if
%>





</table>


<br>


<% if page=1 and not page=zongye then %>
第一页 | 上一页 |
<a href="index.asp?page=<%=page+1%>">下一页</a>|
<a href="index.asp?page=<%=zongye%>">最后页</a>
<% elseif page<>1 and not page =zongye then%>
<a href="index.asp?page=1">第一页</a>|

<a href="index.asp?page=<%=page-1%>">上一页</a>|
<a href="index.asp?page=<%=page+1%>">下一页</a>|
<a href="index.asp?page=<%=zongye%>">最后页</a>|

<% elseif page=zongye then %>
<a href="index.asp?page=1">第一页</a>
<a href="index.asp?page=<%=page-1%>">上一页</a>|
下一页|
最后页|

<% end if %>

<br>

<table border="0" width="100%" id="table1" bgcolor="#D5EAFD" height="31">
<tr>
<td width="591"> </td>
<td>
 </td>
</tr>
</table>


</body>
</html>
...全文
495 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
liu_ff123 2007-03-26
  • 打赏
  • 举报
回复
谢谢大家帮助,lianqizhi的答案是正确详细的,czx4646() ,kimi001() 的也不错,
代码执行OK! 只是点查询结果的 "最后一页" 的时候出现下列错误.答对着照给分! 20分>>

技术信息(用于支持人员)

错误类型:
ADODB.Field (0x80020009)
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
/gxq/phone/index.asp
liu_ff123 2007-03-26
  • 打赏
  • 举报
回复
starchange(星变_浙江教育学院)大哥分我叫我兄弟给你补上了啊!
dingxi666 2007-03-26
  • 打赏
  • 举报
回复
感谢jingxiaoping的支持,starchange(星变_浙江教育学院) 请进如下面地址获取分数!

http://community.csdn.net/Expert/topic/5421/5421283.xml?temp=.7513391
liu_ff123 2007-03-26
  • 打赏
  • 举报
回复
starchange(星变_浙江教育学院) 真的很谢谢你!一时冲动将分数去全打了出去,对不起啊!
浙外 2007-03-26
  • 打赏
  • 举报
回复
楼上的你的代码点最后一页还是会报错的。呵呵。因为最后一页没有判断记录是否够
jingxiaoping 2007-03-26
  • 打赏
  • 举报
回复
<%
keys=request.form("key")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("phone.mdb")
exec="select * from bill where phone like '%"&keys&"%' or phone2 like '%"&keys&"%'"
set rs=server.CreateObject("adodb.recordset")
rs.open exec,conn,1,1
set rs1=server.CreateObject("adodb.recordset")
sql="SELECT sum(Bill.charge) as www FROM Bill WHERE phone like '%"&keys&"%'"
rs1.open sql,conn,1,1
rs.pagesize=20
zongye=rs.pagecount
page=int(request("page"))
if page<=0 then page=1
if request("page")="" then page=1
rs.absolutepage=page
pagestr="index.asp"
linkstr="?"
if keys<>"" then
pagestr=pagestr&linkstr&"key="&keys
linkstr="&"
end if
%>
<html>
<head>
<title>话费查询</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="20" bottommargin="0">

<table border="0" width="100%" id="table1" bgcolor="#D5EAFD">
<tr>
<td width="167">您查询的分机号码是:</td>
<td width="276"> <%response.write(keys) %></td>
<td width="90">话费总计:</td>
<td><%= rs1("www") %> </td>
</tr>
</table>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="10%" height="31" bgcolor="#F7F7F7">拨打日期</td>
<td width="10%" height="31" bgcolor="#F7F7F7">拨打时间</td>
<td width="10%" height="31" bgcolor="#F7F7F7">通话时长</td>
<td width="10%" height="31" bgcolor="#F7F7F7">通话费用</td>
<td width="10%" height="31" bgcolor="#F7F7F7">拨打类型</td>
<td width="10%" height="31" bgcolor="#F7F7F7">机主姓名</td>
<td height="31" bgcolor="#F7F7F7">部门</td>
</tr>
<%
if rs.eof or rs.bof then
response.write("没有找到记录!")
else
for i=1 to rs.pagesize
%>
<tr>
<td width="10%"><%=rs("startdate")%></td>
<td width="10%"><%=rs("starttime")%></td>
<td width="10%"><%=rs("duration")%></td>
<td width="10%"><%=rs("charge")%></td>
<td width="15%"><%=rs("destination")%></td>
<td width="10%"><%=rs("username")%></td>
<td><%=rs("department")%></td>
</tr>
<%
rs.movenext
next
end if
%>
</table>
<br/>
<% if page=1 and not page=zongye then %>
第一页 | 上一页 |
<a href="<%=pagestr%><%=linkstr%>page=<%=page+1%>">下一页</a>|
<a href="<%=pagestr%><%=linkstr%>page=<%=zongye%>">最后页</a>
<% elseif page<>1 and not page =zongye then%>
<a href="<%=pagestr%><%=linkstr%>page=1">第一页</a>|
<a href="<%=pagestr%><%=linkstr%>page=<%=page-1%>">上一页</a>|
<a href="<%=pagestr%><%=linkstr%>page=<%=page+1%>">下一页</a>|
<a href="<%=pagestr%><%=linkstr%>page=<%=zongye%>">最后页</a>|
<% elseif page=zongye then %>
<a href="<%=pagestr%><%=linkstr%>page=1">第一页</a>
<a href="<%=pagestr%><%=linkstr%>page=<%=page-1%>">上一页</a>|
下一页|
最后页|
<% end if %>
<br/>
<table border="0" width="100%" id="table1" bgcolor="#D5EAFD" height="31">
<tr>
<td width="591"> </td>
<td></td>
</tr>
</table>
</body>
</html>
jingxiaoping 2007-03-26
  • 打赏
  • 举报
回复
兄弟你也不试试我的代码呀,唉,再叹声气。
jingxiaoping 2007-03-26
  • 打赏
  • 举报
回复
唉。
浙外 2007-03-26
  • 打赏
  • 举报
回复
呵呵。饥渴的等待分数………………
浙外 2007-03-26
  • 打赏
  • 举报
回复
你在做FOR循环的时候没有考虑到最后一页是否还有足够数量的记录,比方说你有23条记录,你每页显示了5条。前面都没有问题,但是最后一页的时候你就只剩下3条了。所以在FOR循环的时候就出现问题了。没有足够记录了啊。所以你要在FOR循环内加上判断if rs.eof then exit for这样就可以保证万一在循环中间出现记录不够就直接跳出循环。
老大,前面你没给分。这次总要给了吧。
kimi001 2007-03-25
  • 打赏
  • 举报
回复
keys=request.form("key)改成keys=request("keys")
<a href="index.asp?page=<%=page+1%>&keys=<%=keys%>">下一页</a>
czx4646 2007-03-25
  • 打赏
  • 举报
回复
上面写错了,不好意思.应该是:
把keys=request.form("key")这句改成:
if isempty(request.QueryString("key")) then
keys=request.Form("key")
else
keys=request.QueryString("key")
end if
czx4646 2007-03-25
  • 打赏
  • 举报
回复
把keys=request.form("key")这句改成:
if isempty(request.QueryString("keys")) then
keys=request.Form("key")
else
keys=request.QueryString("keys")
end if
这样就好用了,我也遇见过这样的问题.祝成功!
浙外 2007-03-25
  • 打赏
  • 举报
回复
楼上lianqizhi() 的应该是OK的了。分也分点给我。我正在冲5角,老大。靠你了……
浙外 2007-03-25
  • 打赏
  • 举报
回复
你的参数keys没有在点下一页或上一页的时候传递过去,所以就不行了。所以你在上下页连接上除了加page参数传递外还要做个keys参数的传递
cceon 2007-03-25
  • 打赏
  • 举报
回复
帮你顶一下
李睿_Lee 2007-03-24
  • 打赏
  • 举报
回复
搜索条件要传到下个页面。
Zack999 2007-03-24
  • 打赏
  • 举报
回复
<%


keys=request("key")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("phone.mdb")
exec="select * from bill where phone like '%"&keys&"%' or phone2 like '%"&keys&"%'"
set rs=server.CreateObject("adodb.recordset")
rs.open exec,conn,1,1
set rs1=server.CreateObject("adodb.recordset")
sql="SELECT sum(Bill.charge) as www FROM Bill WHERE phone like '%"&keys&"%'"

rs1.open sql,conn,1,1


rs.pagesize=20
zongye=rs.pagecount
page=int(request("page"))
if page<=0 then page=1
if request("page")="" then page=1
rs.absolutepage=page


%>
<html>
<head>
<title>话费查询</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="20" bottommargin="0">

<table border="0" width="100%" id="table1" bgcolor="#D5EAFD">
<tr>
<td width="167">您查询的分机号码是:</td>
<td width="276"> <%response.write(keys) %></td>
<td width="90">话费总计:</td>
<td><%= rs1("www") %> </td>
</tr>
</table>

<table width="100%" border="1" cellpadding="0" cellspacing="0">
<p> 
<tr>
<td width="10%" height="31" bgcolor="#F7F7F7">拨打日期</td>
<td width="10%" height="31" bgcolor="#F7F7F7">拨打时间</td>
<td width="10%" height="31" bgcolor="#F7F7F7">通话时长</td>
<td width="10%" height="31" bgcolor="#F7F7F7">通话费用</td>
<td width="10%" height="31" bgcolor="#F7F7F7">拨打类型</td>
<td width="10%" height="31" bgcolor="#F7F7F7">机主姓名</td>
<td height="31" bgcolor="#F7F7F7">部门</td>
</tr>



<%
if rs.eof or rs.bof then
response.write("没有找到记录!")
else



for i=1 to rs.pagesize
%>


</p>
<tr>
<td width="10%"><%=rs("startdate")%></td>
<td width="10%"><%=rs("starttime")%></td>
<td width="10%"><%=rs("duration")%></td>
<td width="10%"><%=rs("charge")%></td>
<td width="15%"><%=rs("destination")%></td>
<td width="10%"><%=rs("username")%></td>
<td><%=rs("department")%></td>
</tr>



<%
rs.movenext
next
end if
%>





</table>


<br>


<% if page=1 and not page=zongye then %>
第一页 | 上一页 |
<a href="index.asp?key=<%=keys%>&page=<%=page+1%>">下一页</a>|
<a href="index.asp?key=<%=keys%>&page=<%=zongye%>">最后页</a>
<% elseif page<>1 and not page =zongye then%>
<a href="index.asp?key=<%=keys%>&page=1">第一页</a>|

<a href="index.asp?key=<%=keys%>&page=<%=page-1%>">上一页</a>|
<a href="index.asp?key=<%=keys%>&page=<%=page+1%>">下一页</a>|
<a href="index.asp?key=<%=keys%>&page=<%=zongye%>">最后页</a>|

<% elseif page=zongye then %>
<a href="index.asp?key=<%=keys%>&page=1">第一页</a>
<a href="index.asp?key=<%=keys%>&page=<%=page-1%>">上一页</a>|
下一页|
最后页|

<% end if %>

<br>

<table border="0" width="100%" id="table1" bgcolor="#D5EAFD" height="31">
<tr>
<td width="591"> </td>
<td>
 </td>
</tr>
</table>


</body>
</html>
hfdsoft 2007-03-24
  • 打赏
  • 举报
回复
用Cookie或Session保存搜索条件参数。
tantaiyizu 2007-03-24
  • 打赏
  • 举报
回复
把搜索的条件参数也传进去
加载更多回复(5)

28,391

社区成员

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

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