小型排气阀:asp代码解答

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/06 05:47:13
<%
if len(catalogid)=5 then
dhsql=dhsql&" and upclassid='"&catalogid&"'"
set dhrs=conn.execute(dhsql)
response.write"<A href='product_list.asp?catalogid="&dhrs("upclassid")&"'>"&dhrs("nName")&"</A> -->"
elseif len(catalogid)=10 then
dhlen5=left(catalogid,5)
dhsql1=dhsql&" and upclassid='"&dhlen5&"'"
set dhrs1=conn.execute(dhsql1)
response.write"<A href='product_list.asp?catalogid="&dhrs1("upclassid")&"'>"&dhrs1("nName")&"</A> -->"
dhsql=dhsql&" and upclassid='"&catalogid&"'"
set dhrs=conn.execute(dhsql)
response.write"<A href='product_list.asp?catalogid="&dhrs("upclassid")&"'>"&dhrs("nName")&"</A> -->"
end if
%>

请能详细说明代码含义.

就我的理解这是个有级别关系的读取,比如一个树
if len(catalogid)=5 then
dhsql=dhsql&" and upclassid='"&catalogid&"'"
set dhrs=conn.execute(dhsql)
response.write"<A href='product_list.asp?catalogid="&dhrs("upclassid")&"'>"&dhrs("nName")&"</A> -->"
如果catalogid是5位的表示是一级节点输出本身

elseif len(catalogid)=10 then
dhlen5=left(catalogid,5)
dhsql1=dhsql&" and upclassid='"&dhlen5&"'"
set dhrs1=conn.execute(dhsql1)
response.write"<A href='product_list.asp?catalogid="&dhrs1("upclassid")&"'>"&dhrs1("nName")&"</A> -->"
dhsql=dhsql&" and upclassid='"&catalogid&"'"
set dhrs=conn.execute(dhsql)
response.write"<A href='product_list.asp?catalogid="&dhrs("upclassid")&"'>"&dhrs("nName")&"</A> -->"
end if
如果是10位表示二级节点
先取前5位作条件查询输出对应一级节点
然后以10位作条件输出本身节点

其实可以改进为
<%

if len(catalogid)=10 then
dhlen5=left(catalogid,5)
dhsql1=dhsql&" and upclassid='"&dhlen5&"'"
set dhrs1=conn.execute(dhsql1)
response.write"<A href='product_list.asp?catalogid="&dhrs1("upclassid")&"'>"&dhrs1("nName")&"</A> -->"
end if
if len(catalogid)=5 or len(catalogid)=10 then
dhsql=dhsql&" and upclassid='"&catalogid&"'"
set dhrs=conn.execute(dhsql)
response.write"<A href='product_list.asp?catalogid="&dhrs("upclassid")&"'>"&dhrs("nName")&"</A> -->"
end if
%>
能精练点

简单的if else。。。end if语句
判断catalogid的长度,分别执行Sql语句,返回不同的链接