<%
exec="select * from product where 1=1"
set rs=server.createobject("adodb.recordset")
if main_id<>"" then
exec=exec&" and main_id="&main_id
end if
if sub_id<>"" then
exec=exec&" and sub_id="&sub_id
end if
exec=exec&" order by id desc"
rs.open exec,conn,1,1
if rs.eof then
response.Write "此分类暂无产品!"
else
rs.PageSize =8 '每页记录条数
帮我看一下这段代码这样写对吗和里面exec=""与exec=exec&'''的用法,谢谢
答案:1 悬赏:50 手机版
解决时间 2021-04-09 18:53
- 提问者网友:眉目添风霜
- 2021-04-09 00:14
最佳答案
- 五星知识达人网友:白昼之月
- 2021-04-09 01:03
代码这样写没有问题,能够正确运行。只是看着不太整洁而已。
如果想让代码更整洁,可以这样整理一下:
set rs=server.createobject("adodb.recordset")
exec="select * from product where 1=1"
if main_id<>"" then exec=exec&" and main_id="&main_id
if sub_id<>"" then exec=exec&" and sub_id="&sub_id
exec=exec&" order by id desc"
rs.open exec,conn,1,1
if rs.eof then
response.Write "此分类暂无产品!"
else
rs.PageSize =8
......
end if
===========================
看了全部代码后,原来是没有给main_id和sub_id赋值,修改如下:
main_id = trim(request("main_id"))
sub_id = trim(request("sub_id"))
if not isnumeric(main_id) then main_id = 0
main_id = cint(main_id)
if not isnumeric(sub_id) then sub_id = 0
sub_id = cint(sub_id)
set rs=server.createobject("adodb.recordset")
exec="select * from product where 1=1"
if main_id >0 then exec=exec&" and main_id="&main_id
if sub_id >0 then exec=exec&" and sub_id="&sub_id
exec=exec&" order by id desc"
rs.open exec,conn,1,1
if rs.eof then
response.Write "此分类暂无产品!"
else
rs.PageSize =8
如果想让代码更整洁,可以这样整理一下:
set rs=server.createobject("adodb.recordset")
exec="select * from product where 1=1"
if main_id<>"" then exec=exec&" and main_id="&main_id
if sub_id<>"" then exec=exec&" and sub_id="&sub_id
exec=exec&" order by id desc"
rs.open exec,conn,1,1
if rs.eof then
response.Write "此分类暂无产品!"
else
rs.PageSize =8
......
end if
===========================
看了全部代码后,原来是没有给main_id和sub_id赋值,修改如下:
main_id = trim(request("main_id"))
sub_id = trim(request("sub_id"))
if not isnumeric(main_id) then main_id = 0
main_id = cint(main_id)
if not isnumeric(sub_id) then sub_id = 0
sub_id = cint(sub_id)
set rs=server.createobject("adodb.recordset")
exec="select * from product where 1=1"
if main_id >0 then exec=exec&" and main_id="&main_id
if sub_id >0 then exec=exec&" and sub_id="&sub_id
exec=exec&" order by id desc"
rs.open exec,conn,1,1
if rs.eof then
response.Write "此分类暂无产品!"
else
rs.PageSize =8
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯