我做了一个搜索页面,想列出搜索结果后分页显示出来,可是每次都不能正常分页,页面代码如下,请求高人帮助!
能正常显示页面搜索的结果的代码我用红/蓝色标示出来,可是如果按分页的时候结果显示的就是全部数据库结果了,而不是我要搜索的结果了,不知道怎么回事!
<!--#include file="conn.asp"-->
<table width="770"border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
<tr>
<td height="182" valign="top">
<table width="100%"border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
</tr>
</table>
<%
Gnum=Request("Gnum")
sql="SELECT * FROM admin where Gnum & admin like '%"&Gnum&"%'"
set rs=conn.execute(sql)
if rs.eof or rs.bof then
response.write "<script language=javascript>"
response.write "alert('没有找到你所需要删除的数据!');"
response.write "javascript:history.go(-1);"
response.write "</script>"
else
set rs=server.createobject("adodb.recordset")
sql="SELECT * FROM admin where Gnum & admin like '%"&Gnum&"%'"
session("sql")=sql
rs.open sql,conn,1,1
end if
%>
<table width="770"border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr>
<td width="768" bgcolor="#F2F8FF"><table width="100%"border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="10%"><div align="center"><a style="font-size:14px ">编号</a></div></td>
<td width="14%"><div align="center"><a style="font-size:14px ">姓名</a></div></td>
<td width="7%"><div align="center"><a style="font-size:14px ">性别</a></div></td>
<td width="16%"><div align="center"><a style="font-size:14px ">加入日期</a></div></td>
<td width="17%"><div align="center">邮箱</div></td>
<td width="10%"><div align="center"><a style="font-size:14px ">级别</a></div></td>
<td width="16%"><div align="center">电话</div></td>
<td width="10%"><div align="right"><span class="mytext"><font color="#000000">共有</font> <font color="#0000FF">
<% Response.Write(RS.RecordCount) %> '这里能正确显示搜索后的结果数字、但是翻页后又显示成数据库中全部数据的个数了!
</font> <font color="#000000">个</font></span></div></td>
</tr>
</table></td>
</tr>
</table>
<table width="80%" height="2"border="0" cellpadding="0" cellspacing="0" id="dfgdfgds">
<tr>
<td></td>
</tr>
</table>
<%
page=request.querystring("page")
Set rs = Server.CreateObject("ADODB.Recordset")
if session("sql")="" then
sql="select * from information order by id desc"
session("sql")=sql
end if
rs.open session("sql"),conn,3,1
if not rs.bof and not rs.eof then
if page="" then
page=1
end if
pages = 20'每页显示记录数
rs.pagesize = pages
maxpagecount=rs.pagecount
r=clng(rs.RecordCount)'记录总数
rs.absolutepage = page '当前页数
pagestart=page-3 '导航页码
pageend=page+3
if pagestart<1 then 'if语句属于基本的排错处理
pagestart=1
end if
if pageend>maxpagecount then
pageend=maxpagecount
end if '导航页码
end if
%>
<table width="100%"border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr>
<td bgcolor="#F2F8FF"><center>
<%row_count=1
i=0
do while not rs.eof and rcount < rs.pagesize
%>
<table width="768"border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="569" height="13"><div align="right"><font color="#0000FF" size="2"> </font>
<table width="80%" height="3"border="0" cellpadding="0" cellspacing="0" id="123123">
<tr>
<td></td>
</tr>
</table>
<table width="568" border="0" align="left" cellpadding="0" cellspacing="0" bordercolordark="#ffffff" berdorcoorlight="#000000">
<tr align="center" bgcolor="#F2F8FF">
<td width="76" align="center"><SPAN class=mytext><a href="userdetail.asp?Gnum=<%=rs("Gnum")%>"><%=rs("Gnum")%></a></SPAN> </font></a></td>
<td width="110" align="center"><div align="center"><font color="#0033FF" size="2"> <span class="mytext"><%=rs("admin")%></span></font></div></td>
<td width="48" align="center"><div align="center"><%=rs("Gsex")%></div></td>
<td width="129" align="center"><div align="center"><%=rs("Gtime")%></div></td>
<td width="130" align="center"><%=rs("Gmail")%></td>
<td width="75" align="center"><div align="center">
<%if rs("Gjibie")="正式会员" then%>
<a style="font-size:13;color:#000000">正式会员</a>
<%end if%>
<%if rs("Gjibie")="试用客户" then%>
<a style="font-size:13;color:#0000CC" href="as.asp?id=<%=rs("id")%>&action=yes">试用客户</a>
<%end if%>
</div></td>
</tr>
</table>
<div align="left"><font color="#0000FF" size="2"></font> </div>
</div></td>
<td width="123"><div align="center"><%=rs("Gtel")%></div></td>
<td width="29"><div align="center"><a href="as.asp?action=bj&id=<%=rs("id")%>#123">修改</a></div></td>
<td width="47"><div align="center"><a href="del.asp?action=del&id=<%=rs("id")%>" onClick="return confirm('您确定删除此会员吗?注意:此操作无法恢复!');">删除</a></div></td>
</tr>
</table>
<table width="80%" height="2"border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<%if row_count mod 1 =0 then%>
<%end if%>
<%
rs.movenext
rcount=rcount+1
i=i+1
row_count=row_count+1
loop
set rs=nothing
%>
</center></td>
</tr> '上面这个表格分的分页就根本不按搜索结果列项目了,而是直接列出数据库中的所有的项目,问题就是这个!
<table width="770" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
<td bgcolor="#749AEC"><div align="right" class="mytext">
<% response.write "<a href='dopage.asp?page=1'><IMG alt='' src='img/First.gif' border=0></a>"%>
<span class="style8">
<% for i=pagestart to pageend
if i=0 then
i=1
end if
strurl="<a href='dopage.asp?page="&i&"'><font size=1 color=000000>["&i&"]</font></a>"
response.write " "
response.write strurl
response.write " "
response.write " "
next
%>
<% response.write "<a href='dopage.asp?page="&maxpagecount&"'><img src='img/Last.gif' width='9' height='8' border=0></a>"%>
<span class="style7">
<%response.write "<font size=2 color=000000>"&page&"/"&maxpagecount&"页</font>"%>
</span></span></div>
<div align="right"></div></td>
</tr>
<tr> </tr>
<tr>
<td bgcolor="#F2F8FF"></td>
</tr>
</table> '这里也能正确显示搜索后的分页结果、但是翻页后又显示成数据库中全部数据的分页了!
[此贴子已经被作者于2006-2-17 11:41:55编辑过]