求助!多条件查询下分页问题

stephen1 2005-03-23 04:14:17
我已经按各位老师的指点改正了,可还是不行。请老师们继续指教(系统提示:参数类型不正确,或不在可以接受的范围之内,或与其他参数冲突。)
本页代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
set rs=server.createObject("adodb.recordset")
pid=request.form("search")
set cn=server.createobject("adodb.connection")
cn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("student.mdb")
condition=request.form("select1")

if condition="姓名" then //如果把条件去掉,翻页功能就可实现。
exec="select * from student where 姓名 like '%"& pid &"%'"

elseif condition="班级" then
exec="select * from student where 班级 like '%"& pid &"%'"

end if

rs.open exec,cn,1,1

if rs.recordcount>0 then '如果有记录
rs.pagesize=2 '每页最多显示2条纪录
'从URL获取当前要显示的页
page=cint(request("page"))
'页面参数异常处理
if page="" then page=1
if page<1 then page=1
if page>= rs.pagecount then page=rs.pagecount
rs.absolutepage=page '当前页为page参数指定的页
%>
<% for i=1 to rs.pagesize '根据pagesize参数的大小循环显示当前页中的纪录

next
end if

'显示翻页按钮
if page>1 then
response.write "<a href="&request.servervariables("document_name")&"?page=1>第一页</a> "
response.write "<a href="&request.servervariables("document_name")&"?page="&(page-1)&">上一页</a> "
end if
if page<>rs.pagecount then

response.write "<a href="&request.servervariables("document_name")&"?page="&(page+1)&"search="&pid&"select1="&condition&">下一页</a> " //本句我尝试将参数传到下一页,可不能成功。

response.write "<a href="&request.servervariables("document_name")&"?page="&rs.pagecount&">最后一页</a> "
end if
response.write"页码:"&page&"/"&rs.pagecount
%>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>查询结果</title>
</head>

<body>
<table width="745" height="56" border="1"><!--DWLayoutTable-->
<tr>
<th width="62" scope="col">班级</th>
<th width="62" scope="col">姓名</th>
<th width="75" scope="col">学号</th>
<th width="185" scope="col">专业</th>
<th width="84" scope="col">宿舍</th>
<th width="69" scope="col">宿舍电话</th>
<th width="69" scope="col">移动电话</th>
<th width="91" scope="col"> </th>
</tr>
<% for recordnums=1 to rs.pagesize %>
<tr>
<td height="31"> <%= rs("班级")%></td>
<td><%= rs("姓名")%> </td><td><%= rs("学号")%></td>
<td><%= rs("专业")%></td>
<td><%= rs("宿舍")%> </td>
<td><%= rs("宿舍电话")%> </td>
<td><%= rs("移动电话")%></td>
<td><% response.write"<a href='searchsdresult.asp?ID="&rs("ID")&"'>"%>
查看详情</td>
</tr>

<% rs.movenext
if rs.eof then
exit for
end if
next
rs.close
cn.close
set rs=nothing
set cn=nothing%>
</table>

</body>
</html>
...全文
102 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
stephen1 2005-03-23
  • 打赏
  • 举报
回复
非常感谢两位的帮助,在你们的指点下我成功了。但最后还有一个小问题,那就是为什么我计算的总页数要比实际多一页呢,也即rs.pagecount的值比实际的总页数多了一。谢谢!
hhjjhjhj 2005-03-23
  • 打赏
  • 举报
回复
condition=request.form("select1")
改成
condition=request("select1") '这样无论select1来自FORM还是servervariables都可以取到
myvicy 2005-03-23
  • 打赏
  • 举报
回复
response.write "<a href="&request.servervariables("document_name")&"?page="&(page+1)&"&search="&pid&"&select1="&condition&">下一页</a> " //本句我尝试将参数传到下一页,可不能成功。
传参那里少加了&符号。
myvicy 2005-03-23
  • 打赏
  • 举报
回复
if condition="姓名" then //如果把条件去掉,翻页功能就可实现。
exec="select * from student where 姓名 like '%"& pid &"%'"

elseif condition="班级" then
exec="select * from student where 班级 like '%"& pid &"%'"

end if

---------------------------------------------------------------------------
把这段代码用下面这句替代试试!

exec="select * from student where "&condition&" like '%"& pid &"%'"

28,391

社区成员

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

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