求教多条件查询后分页出错问题

踩西瓜皮上线 2007-08-21 04:59:56
我做了个多条件查询记录页面,查询没有出错,显示一也没有问题,但是我的查询数据量非常大,一页显示肯定不行,我试了个分页技术,(分页效果在静态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语句的变化情况见附贴图片======

求教高手多条件查询后分页出错问题
...全文
128 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
踩西瓜皮上线 2007-08-21
  • 打赏
  • 举报
回复
我也添加了保证条件有效的设置1=1 还是不行啊 !好像要把sql语句存在session变量里面吧,但是不知道改这么存!!
jingxiaoping 2007-08-21
  • 打赏
  • 举报
回复
=====接受查询条件=====
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 1=1"
=====生成动态sql语句====
if bianhao<>"" then sql=sql&" and member_bianhao='"&bianhao&"'"
if zhaopian<>"不限" then sql=sql&" and member_photo<>''"
if sex<>"不限" then sql=sql&" and member_sex='"&sex&"'"
if shouru<>"" then sql=sql&" and member_earn>='"&shouru&"'"
……
======处理全为空的情况=====
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%>

28,391

社区成员

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

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