Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Categories
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

anderzzo
Starting Member

5 Posts

Posted - 19 June 2001 :  04:53:33  Show Profile  Visit anderzzo's Homepage
I'm trying to display some categories and sub-categories in a dropdown box, the table looks like this:

CatID (counter, ID)
CatName (name)
CatBel (if it's a sub: ID of the category it belongs to, if it's a main category: "none")

to get all the main categories I write:


<%
SQL="Select * From Categ Where CatBel='none'"
Set ca=Conn.Execute(SQL)
Do Until ca.EOF
%>
<option value="<%=ca("CatID")%>"><%=ca("CatName")%></option>
<%
ca.MoveNext
Loop
ca.Close
Set ca=Nothing
%>


but the problem starts when I want to display all the subs I could write:


<%
SQL="Select * From Categ Where CatBel='none'"
Set ca=Conn.Execute(SQL)
Do Until ca.EOF
%>
<option value="<%=ca("CatID")%>"><%=ca("CatName")%></option>
<%
SQL2="Select * From Categ Where CatBel='"& ca("Catbel") &"'"
Set tac=Conn.Execute(SQL2)
Do Until tac.EOF
%>
<option value="<%=tac("CatID")%>"><%=ca("CatName")%>/<%=tac("CatName")%></option>
<%
tac.MoveNext
Loop
tac.Close
Set tac=Nothing
Next
ca.MoveNext
Loop
ca.Close
Set ca=Nothing
%>


But then I just get one level deep :(
How do I display all the subs?

Please I really need help with this!

Thanx

-=Data-Doktorn=-
Snart på en dator nära dig!

Edited by - anderzzo on 19 June 2001 04:56:18

davemaxwell
Access 2000 Support Moderator

USA
3020 Posts

Posted - 19 June 2001 :  12:24:38  Show Profile  Visit davemaxwell's Homepage  Send davemaxwell an AOL message  Send davemaxwell an ICQ Message  Send davemaxwell a Yahoo! Message
OK. What does CatBel contain? I think your problem is your SQL2 statement. Shouldn't it be....

SQL2="Select * From Categ Where CatBel='"& ca("CatID") &"'"



Dave Maxwell
--------------
Proud to be a "World Class" Knucklehead
Go to Top of Page

anderzzo
Starting Member

5 Posts

Posted - 21 June 2001 :  16:28:35  Show Profile  Visit anderzzo's Homepage
Sorry, just a typo, should be
SQL2="Select * From Categ Where CatID='"& ca("Catbel") &"'"

CatBel contains if it's a sub: ID of the category it belongs to, if it's a main-category: "none"

I could write a new sql-statement and a loop in each loop to display a new category, if it exist, but there's got to be a smarter way!

This is how it should work, first I display all categories that have "none" in CatBel, for each category I need to look in the DB and see if there's a category that have the category ID in CatBel and then display it, and then do the same procedur with the new category.

So basicly:
If cat1 is a main category display it, then look in the DB if there's a category that have cat1's ID in CatBel, if there is display it, and then look again in the DB and see if there's a category that have the new categorys ID in CatBel, and do this until no more categories can be found!

Hope you understand! And sorry for my bad english :D

-=Data-Doktorn=-
Snart på en dator nära dig!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000 Version 3.4.07