ASP example Tutorial: ASP infinite level display classification code

Source: Internet
Author: User
Tags add end sql

To facilitate the use of categories, I have defined a category table category, where the field is
ID (AutoNumber) cat_name (category name) parent_id (parent ID, corresponding to this table ID) cat_order (order) Is_show (whether) u_id (this is used to distinguish between news classification, product classification, or other classification), for convenience, I put all these categories in this table.
When adding categories to customers, the results are too many categories, the front desk display, they all show up, very long. Customers to change their opinions, request that they be changed to click on a large category, can be their subcategories to display, and each category below there is a dotted line, and large categories in front of a picture plus, expand to become a minus sign.
<script>
function fd (id,num)
{
t=$ ("C" +id+ "_1"). Style.display;

if (t== "None")
{
t1= "Block";
T2= "Images/fll_34.gif";
}
Else
{
T1= "None";
T2= "Images/fll_34.gif";
}
for (i=1;i<=num;i++)
{
$ ("C" +id+ "_" +i). Style.display=t1;
$ ("D_" +id). Src=t2;
}
}
function $ (ID)
{
return document.getElementById (ID);
}
</script>
This is the ASP infinite level display classification code, and give these classifications with ID

<%
' Function: ASP infinite level display classification +js display and hide
' Parameters: parent_id for the Father Id,stype for news, products, articles, large categories
' Original articles, reprint please keep some information, thank you
function cat111 (parent_id,stype)
Set Rs1 =server.createobject ("Adodb.recordset")
Sql= "Select cat_name,cat_id,parent_id from category where parent_id=" &parent_id& "and u_id=" &stype& " and is_show=1 ORDER by cat_order ASC "
Set Rs1=conn.execute (SQL)
If rs1.eof Then
Else
if (depath>2) then
Display2= "None"
Else
Display2= "Block"
End If
Dim j
J=1
Do as not rs1.eof
cat_name1 = Rs1 ("Cat_name")
CAT_ID1 = Rs1 ("cat_id")
Parent_id1=rs1 ("parent_id")
' ****************** below is the ****************** you want to show '
M9=0
Sql2= Select COUNT (cat_id) as T from category where parent_id= "&cat_id1&" and u_id= "&stype&"
Set Rs2=server.createobject ("Adodb.recordset")
Set Rs2=conn.execute (SQL2)
If not rs2.eof then
M9=rs2 ("T")
Else
M9=0
End If
Rs2.close

if (depath<=2) then
mgif= "Images/-.gif"
A= "Block"
Else
if (m9>0) then
mgif= "Images/+.gif"
Else
mgif= "Images/-.gif"
End If
if (depath=4) then
A= "Block"
Else
A= "None"
End If
End If


Catstr=catstr & "<tr id=" "C" &parent_id& "_" &j& "" style= "" Display: &a& "" "><td Width= "" align= "" Center "" valign= "" Middle "" class= "" Dotted_class "" ></td><td class= "" Dotted_class leftcatcss "" > "
if (m9>0) then
catstr=catstr& "<a href=" "javascript:void (0);" "_fcksavedurl=" "" javascript:void (0); "" "_fcksavedurl=" "" Javascript:void (0); "" "Onclick=" FD ("&cat_id1&", "&m9&") ">" &vbnewline
Else
catstr=catstr& "<a href=" "products.asp?id=" &cat_id1& "" "target=" "_blank" ">" &vbnewline
End If
For I=1 to Depath
catstr=catstr& ""
Next
catstr=catstr&cat_name1& "</a></td></tr>" &vbnewline
M9=0

Sql2= ' select cat_name,cat_id from category where parent_id= ' &parent_id1& ' and u_id= ' &stype& ' ORDER by Cat_order ASC "
Set Rs2=server.createobject ("Adodb.recordset")
Set Rs2=conn.execute (SQL2)
If not rs2.eof then
Depath=depath+4
Call cat111 (Cat_id1,stype)
End If
Rs2.close
Set rs2=nothing
Depath=depath-4
' ****************** above is the ****************** you want to show '
J=j+1
Rs1.movenext
Loop
End If
Rs1.close
Set rs1=nothing
End Function
%>
Before you use this function, add
Catstr= ""
Then call, the following dotted line added to the CSS in the dotted_class inside, so it's done.
Note: Here is a table of rows, and other lines to put together, do not add to the TD inside.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.