我做了个多条件查询记录页面,查询没有出错,显示一也没有问题,但是我的查询数据量非常大,一页显示肯定不行,我试了个分页技术,(分页效果在静态sql语句上也没有问题),但是当sql语句是动态的时候,分页就出错了。看了阳光白雪斑竹回答别人的帖子,有点启发,把sql语句存在session变量里面,但是分页参数俺不是太懂,现将部分代码贴出来,望高手解决啊!!
=====接受查询条件=====
bianhao=trim(replace(request.form("bianhao"),"'","''"))
zhaopian=request.form("zhaopian")
sex=request.form("sex")
nianling=trim(replace(request.form("nianling"),"'","''"))
……
=====写出sql语句=====
sql="select * from member where "
=====生成动态sql语句====
if bianhao<>"" then sql=sql&" member_bianhao='"&bianhao&"' and"
if zhaopian<>"不限" then sql=sql&" member_photo<>'' and"
if sex<>"不限" then sql=sql&" member_sex='"&sex&"' and"
if shouru<>"" then sql=sql&" member_earn>='"&shouru&"' and"
……
======处理全为空的情况=====
if right(sql,5)="where" then sql=left(sql,clng(len(sql))-5) /查询条件为空时,去掉上面sql语句的"where"
if right(sql,3)="and" then sql=left(sql,clng(len(sql))-3) /去掉语句最后的“and”
sql=sql&" order by member_reg asc"
rs.open sql,conn,1,1
====开始分页代码=====问题就出在下面的代码里面
IF (rs.State =adStateClosed) or (rs.BOF=true and rs.EOF =true) or rs.RecordCount=0 THEN
RESPONSE.Write"<BR><BR> 暂时还没有会员记录... <br>"
ELSE
dim page,ipage
rs.pagesize=10
page=request("Page")
pages(page)
page=clng(Page)
if page > rs.pagecount then response.redirect "login.asp"
if page=empty then page=1
rs.absolutepage=page
for ipage=1 to rs.pagesize
%>
……………… / 在此省略 输出格式
<%Rs.movenext
If rs.eof Then exit For
Next%>
<%
if page=empty then page=1
if page < 1 then page=1
if page > rs.pagecount then page=rs.pagecount
%>
共<font color=ff0000><b><%=rs.recordcount%></b></font>条记录 共<font color=ff0000><b><%=rs.pagecount%></b></font>页</td>
<td width="89" align="center" valign="bottom" style="color:#A5537B;padding-bottom:7px;">第
<select class=dh name=select onChange=mychange(value) size="1" style="font-family: 宋体;border:1px solid; font-size: 9pt;color:#333333;">
<%for i=1 to rs.pagecount%>
<%if i=page then%>
<option value=<%=Request.ServerVariables("SCRIPT_NAME")%>?Page=<%=i%> selected><%=i%></option>
<%else%>
<option value=<%=Request.ServerVariables("SCRIPT_NAME")%>?Page=<%=i%>><%=i%></option>
<%end if%>
<%next%>
</select>
页 </td>
<td width="324" align="center" style="color:#A5537B;">
<%if page<>1 then%>
<a href=<%=Request.ServerVariables("SCRIPT_NAME")%>?Page=1><img src="images/index.gif" alt="首页" width="72" height="17" hspace="3" border="0"></a><a href=<%=Request.ServerVariables("SCRIPT_NAME")%>?Page=<%=(page-1)%>><img src="images/pre01.gif" alt="上一页" width="72" height="17" hspace="3" border="0"></a><%else%><img src="images/index.gif" alt="首页" width="72" height="17" hspace="3" border="0"><img src="images/pre01.gif" alt="上一页" width="72" height="17" hspace="3" border="0"><%end if%><% if page<>rs.pagecount then%><a href=<%=Request.ServerVariables("SCRIPT_NAME")%>?Page=<%=(page+1)%>><img src="images/next01.gif" alt="下一页" width="72" height="17" hspace="3" border="0"></a><a href=<%=Request.ServerVariables("SCRIPT_NAME")%>?Page=<%=rs.pagecount%>><img src="images/end.gif" alt="尾页" width="72" height="17" hspace="3" border="0"></a>
<%else%><img src="images/next01.gif" alt="下一页" width="72" height="17" hspace="3" border="0"><img src="images/end.gif" alt="尾页" width="72" height="17" hspace="3" border="0">
<%end if%><script language=javascript>
function mychange(v){
if (v==""){}
else{
window.open (v,target="_self")
}
}
</script> </td>
</tr>
</table>
<%
rs.close
set rs=nothing
END IF%>
======我做了所有全为空时sql语句输出测试分页前后sql语句的变化情况见附贴图片======