一点小问题

stephen1 2005-03-23 06:16:24
我实现了分页功能,但是出现了两个小问题:一是为何我的页数显示比实际页数多1;另一个是当我的查询结果仅有一个记录符合时,不能被显示出来。哪位劳神帮我看看,下面是我的代码:感谢。

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
dim exec,cn,pid,condition,i
set rs=server.createObject("adodb.recordset")
pid=request("search")
set cn=server.createobject("adodb.connection")
cn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("student.mdb")
condition=request("select1")
if condition="姓名" then
exec="select * from student where 姓名 like '%"& pid &"%' "


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

end if

rs.open exec,cn,1,1

if rs.recordcount>0 then '如果有记录
rs.pagesize=10 '每页最多显示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
rs.movenext '纪录指针下移
if rs.eof then exit for '如果到达纪录集底部则退出循环
next

end if
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<%
'显示翻页按钮
if page>1 then
response.write "<a href="&request.servervariables("document_name")&"?page=1&search="&pid&"&select1="&condition&">第一页</a> "
response.write "<a href="&request.servervariables("document_name")&"?page="&(page-1)&"&search="&pid&"&select1="&condition&">上一页</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&"&search="&pid&"&select1="&condition&">最后一页</a> "
end if
response.write"共:"&rs.recordcount&"条记录;"
response.write"页码:"&page&"/"&rs.pagecount
%>
<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>
...全文
78 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

28,390

社区成员

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

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