日期:2014-05-17  浏览次数:20842 次

听说这里高手多 求助查询结果分页不正确的问题
一共 2个页面

1.asp:代码

<html>
<head>
<title>提交页</title>
</head>
<body>
<form name="form1" method="post" action="2.asp?">
  <label>
  <input type="text" name="SearchForm" id="SearchForm">
  </label>
  <label>
  <input type="submit" name="Submit" value="提交">
  </label>
  </form>
</body>
</html>


2.asp:代码

<!-- #include file="db.inc.asp"-->
<html>
<head>
<title>会员查询</title>
</head>

<body>

<%
dim tname
If request.form("SearchForm")<>"" Then
tname=request("SearchForm")
end if
sql="select * from user,info where u_id=i_uid and i_name like '%"&tname&"%'"
set rst=server.createobject("adodb.recordset")
rst.open sql,conn,1,1
%>

<%
rst.pagesize=3'指定每页的记录条数 3条
cpage=request.QueryString("cpage")'获取地址栏变量参数
if cpage="" then cpage=1'if语句 如果没有传递过来page参数的页 直接赋于第一页的值
rst.absolutepage=cpage'指定page为当前页
for i=1 to rst.pagesize'利用for循环在每页显示rs.pagesize属性中指定的记录数 就是每页循环显示3条
if rst.eof then'当每页循环显示达到数据库最后一条记录时
exit for'就退出循环,就退出for循环
end if
%>

<tr>
<td align="center"><%=rst("u_id")%></td>
<td align="center"><%=rst("u_user")%></td>
<td align="center"><%=rst("i_name")%></td>
<td align="center"><%=rst("i_sex")%></td>
<td align="center"><%=rst("i_age")%></td>
</tr>

<%
rst.movenext
next
%>  


   
  当前:第<%=cpage%>页 共有:<%=rst.pagecount%>页 共有:<%=rst.recordcount%>条记录

<%
if cpage=1 then'如果当前为第一页(也就是首页),那么显示首页两字,没有链接,否则提供直接跳转到首页的链接
%>
首页
<%else%>
<a href="2.asp?cpage=1&tname=<%=tname%>">首页</a>
<%end if%>
<%
if cpage=1 then'如第一页时,链接失效,反过来,链接到当前面的上一页,这里使用curpage-1,就是用当前的页数减去1,得到上一页
%>
上一页
<%else%>
<a href="2.asp?cpage=<%=cpage-1%>&tname=<%=tname%>">上一页</a>
<%end if%>
<%
if rst.pagecount<cpage+1 then'这里需要使用rs.pagecount这个属性来比较,假如总页数小于当前页数加1的值,那表明这就是第后一页,链接将失效,否则链接到下一页
%>
下一页
<%else%>
<a href="2.asp?cpage=<%=cpage+1%>&tname=<%=tname%>">下一页</a>
<%end if%>
<%
if rst.pagecount<cpage+1 then'和下一页的功能一样判定出是最后页时链接失效,否则将当前页指定为rs.pagecount总页数
%>
尾页
<%else%>
<a href="2.asp?cpage=<%=rst.pagecount%>&tname=<%=tname%>">尾页</a>
<%end if%>
<%
rst.close
%>
</body>
</html>

这是第一页的地址 http://localhost/elon/2.asp? (可以正常显示查询结果)
这是第二页的地址 http://localhost/elon/2.asp?cpage=2&tname=黄 (不能正常显示查询结果)
这是第三页的地址变这样 http://localhost/elon/2.asp?cpage=3&tname= (不能正常显示查询结果)

搞不懂原因啊

------解决方案--------------------
<form name="form1" method="get" action="2.asp?">

才是通过地址得到参数的