if语句嵌套了十几层,有没有更好的方法_已OK
如图:使用if语句判断搜索,得判断十多次,具体我都有点说不清了,如下代码(有点多),用是有用,但觉得很繁锁,我一直是这么用的,如图,现在有4个条件,if语句写了那么多,如果条件更多的话那if语句则会更多,不知道不没有更好的判断方式.<%
set rs = server.CreateObject("adodb.recordset")
keytext = replace(trim(Request("keytext")),"'","") '查询关键字
BigClassName = replace(trim(Request("BigClassName")),"'","") '类别
s_cl = replace(trim(Request("s_cl")),"'","") '范围
s_year = trim(Request("s_year")) '年
sql="select * from [product] where auditing=true "
if isnull(s_year) or s_year="" then
if isnull(s_cl) or s_cl="" then
if isnull(keytext) or keytext="" then
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' order by sort",conn,1,1
end if
else
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " and like '%"&keytext&"%' order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' and [name] like '%"&keytext&"%' order by sort",conn,1,1
end if
end if
else
if s_cl=1 then
if isnull(keytext) or keytext="" then
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' order by sort",conn,1,1
end if
else
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " and like '%"&keytext&"%' order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' and [name] like '%"&keytext&"%' order by sort",conn,1,1
end if
end if
elseif s_cl =2 then
if isnull(keytext) or keytext="" then
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' order by sort",conn,1,1
end if
else
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " and [content] like '%"&keytext&"%' order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' and [content] like '%"&keytext&"%' order by sort",conn,1,1
end if
end if
end if
end if
else
if isnull(s_cl) or s_cl="" then
if isnull(keytext) or keytext="" then
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " and [date] like '%"&s_year&"%' order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' and [date] like '%"&s_year&"%' order by sort",conn,1,1
end if
else
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " and [name] like '%"&keytext&"%' and [date] like '%"&s_year&"%' order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' and [name] like '%"&keytext&"%' and [date] like '%"&s_year&"%' order by sort",conn,1,1
end if
end if
else
if s_cl=1 then
if isnull(keytext) or keytext="" then
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " and [date] like '%"&s_year&"%' order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' and [date] like '%"&s_year&"%' order by sort",conn,1,1
end if
else
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " and [name] like '%"&keytext&"%' and [date] like '%"&s_year&"%' order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' and [name] like '%"&keytext&"%' and [date] like '%"&s_year&"%' order by sort",conn,1,1
end if
end if
elseif s_cl =2 then
if isnull(keytext) or keytext="" then
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " and [date] like '%"&s_year&"%' order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' and [date] like '%"&s_year&"%' order by sort",conn,1,1
end if
else
if isnull(BigClassName) or BigClassName="" then
rs.open sql & " and [content] like '%"&keytext&"%' and [date] like '%"&s_year&"%' order by sort",conn,1,1
else
rs.open sql & " and BigClassName='"&BigClassName&"' and [content] like '%"&keytext&"%' and [date] like '%"&s_year&"%' order by sort",conn,1,1
end if
end if
end if
end if
%>_
[[it] 本帖最后由 yangliangy 于 2008-3-19 22:06 编辑 [/it]]