取第m条到n条记录带查询条件问题

yyusnO 2008-12-10 09:57:00
asp+access

以下是代码段

<%'上面是查询
allcount=rsl.recordcount
IF allcount mod 20 <>0 THEN
S=INT(ALL/20+1)
ELSE
S=ALL/20
END IF%>
<%
m=1
n=20
FOR i=1 TO S%>
<div id=page<%=i%>>
<table>
<tr><td>表头</td></tr>
<%Set rs = Server.CreateObject ("ADODB.Recordset")
if n=20 then
sqll="select top "&ss&" * from [u_mains] where"
else
sqll="select top "&ss&" * from [u_mains] where id not in (select top "&sss&" id from u_mains order by id asc) and"
end if

if s_pc="1" then sqll=sqll&" u_pc='"&i_pc&"' and"
if s_rq="1" then sqll=sqll&" u_date between #"&InTime1&"# and #"&InTime2&"# and"
if s_cx="1" then sqll=sqll&" u_cx='"&i_cx&"' and"
if s_name="1" then sqll=sqll&" u_name='"&i_name&"' and"
if s_sex="1" then sqll=sqll&" u_sex='"&i_sex&"' and"
if s_card="1" then sqll=sqll&" u_card='"&i_card&"' and"
if s_tel="1" then sqll=sqll&" u_tel='"&i_tel&"' and"
if s_address="1" then sqll=sqll&" u_address like '%"&i_address&"%' and"
if right(sqll,5)="where" then sqll=left(sqll,clng(len(sqll))-5) ''''解决所有参数都为空的情况
if right(sqll,3)="and" then sqll=left(sqll,clng(len(sqll))-3) ''''去掉参数最后的and
sqll=sqll&" order by id asc"
response.Write(""&sqll&"")
rs.Open sqll,conn,1,1
if rs.EOF and rs.BOF then
Response.Write "暂时还没有内容"
else
page_count=m
do while not rs.eof%>
<tr><td>显示内容</td></tr>
<%page_count=page_count+1
rs.MoveNext
Loop
end if%>
</table>
</div>
<%N=N+20
M=M+20%>
<%NEXT%>


这段如果加上条件查询的话,就不输出,请高手帮忙哦
...全文
93 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
layers2323 2008-12-10
  • 打赏
  • 举报
回复
sqll="select top "&ss&" * from [u_mains] where id not in (select top "&sss&" id from u_mains where 条件字符串 order by id asc) and 条件字符串"
zjsfdxbao 2008-12-10
  • 打赏
  • 举报
回复
if s_pc="1" then sqll=sqll&" u_pc='"&i_pc&"' and"
if s_rq="1" then sqll=sqll&" u_date between #"&InTime1&"# and #"&InTime2&"# and"
if s_cx="1" then sqll=sqll&" u_cx='"&i_cx&"' and"
if s_name="1" then sqll=sqll&" u_name='"&i_name&"' and"
if s_sex="1" then sqll=sqll&" u_sex='"&i_sex&"' and"
if s_card="1" then sqll=sqll&" u_card='"&i_card&"' and"
if s_tel="1" then sqll=sqll&" u_tel='"&i_tel&"' and"
if s_address="1" then sqll=sqll&" u_address like '%"&i_address&"%' and"
if right(sqll,5)="where" then sqll=left(sqll,clng(len(sqll))-5) ''''解决所有参数都为空的情况
if right(sqll,3)="and" then sqll=left(sqll,clng(len(sqll))-3) ''''去掉参数最后的and
这一堆附加条件应该也要加到内联表里面
yyusnO 2008-12-10
  • 打赏
  • 举报
回复
明白了,我自己改改
zjsfdxbao 2008-12-10
  • 打赏
  • 举报
回复
分页的语句没问题
yyusnO 2008-12-10
  • 打赏
  • 举报
回复
哦,那我红色的语句应该怎么写哦~~luxu001207
Atai-Lu 2008-12-10
  • 打赏
  • 举报
回复
sqll="select top "&ss&" * from [u_mains] where id not in (select top "&sss&" id from u_mains order by id asc) and"
红色这句的条件跟主句的条件要一样,排序也一样
yyusnO 2008-12-10
  • 打赏
  • 举报
回复
wangkk125
这样试验了,不好用,取得是没有条件的数据
wangkk125 2008-12-10
  • 打赏
  • 举报
回复
sqll="select top "&ss&" * from [u_mains] where id not in (select top "&sss&" id from u_mains order by id asc) and"+条件字符
改成这样
sqll="select top "&ss&" * from [u_mains] where id not in (select top "&sss&" id from u_mains where 条件字符 order by id asc)
yyusnO 2008-12-10
  • 打赏
  • 举报
回复
错误倒是没有,就是
21select top 20 * from [u_mains] where id not in (select top 20 id from u_mains order by id asc) and u_pc='2' order by id asc
这是第2个层里显示的
显示的和第一个层的数据是一样的
如果不加条件的话,就都能显示出来,不包下面的条件
if s_pc="1" then sqll=sqll&" u_pc='"&i_pc&"' and"
if s_rq="1" then sqll=sqll&" u_date between #"&InTime1&"# and #"&InTime2&"# and"
if s_cx="1" then sqll=sqll&" u_cx='"&i_cx&"' and"
if s_name="1" then sqll=sqll&" u_name='"&i_name&"' and"
if s_sex="1" then sqll=sqll&" u_sex='"&i_sex&"' and"
if s_card="1" then sqll=sqll&" u_card='"&i_card&"' and"
if s_tel="1" then sqll=sqll&" u_tel='"&i_tel&"' and"
if s_address="1" then sqll=sqll&" u_address like '%"&i_address&"%' and"
yyusnO 2008-12-10
  • 打赏
  • 举报
回复
不是分页,是分层显示,要做打印的哦,层的id不同
zjsfdxbao 2008-12-10
  • 打赏
  • 举报
回复
不如你把错误的SQL抛出来大家看下更清晰,肯定是SQL字符串的问题
文盲老顾 2008-12-10
  • 打赏
  • 举报
回复
是要实现分页?
yyusnO 2008-12-10
  • 打赏
  • 举报
回复
这段打错了,all应该是allcount

<%'上面是查询
allcount=rsl.recordcount
IF allcount mod 20 <>0 THEN
S=INT(ALL/20+1)
ELSE
S=ALL/20
END IF%>
yyusnO 2008-12-10
  • 打赏
  • 举报
回复
这段打错了,all应该是allcount

<%'上面是查询
allcount=rsl.recordcount
IF allcount mod 20 <>0 THEN
S=INT(ALL/20+1)
ELSE
S=ALL/20
END IF%>

28,409

社区成员

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

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