Print Page | Close Window

Unlimited subcategories- I’m so confused!

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5889
Printed Date: 31 March 2026 at 8:41am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Unlimited subcategories- I’m so confused!
Posted By: FLATLINE
Subject: Unlimited subcategories- I’m so confused!
Date Posted: 22 September 2003 at 9:07am

Yo everyone!

I'm working on an ASP application which has a table with an unlimited number of categories and subcategories. This is how it works:

Every category has:
cat_id - Unique autonumber of each category
cat_parent - The cat_id of the parent category
cat_name - The display name of the category

The hierrarchy (sp?) works like this:
On top there are the categories which have 0 as their cat_parent, that indicates a root category. Below, there are all the subcategories which have the main category's cat_id set up as their cat_parent. Then we have all the subcategories which have the previous subcategory's cat_id as their cat_parent and so on.

What I'm trying to do is make a SELECT form tag (drop down box) with all the categories and subcategories as options. But the trick is make it so every subcategory will be indented relating to its parent category. For examble:

  • Animals
    • Rabbits
    • Dogs
    • Cats
  • Facilities
    • Houses
      • Apartment
        • 2-3 Floors
        • 4-12 Floors
        • 12+ Floors
      • Private
    • Factories
    • Other

Notice the construction under the Facilities main category: The 2-3 Floors for example, is a subcategory under the subcategory Apartment which is a subcategory of Houses which in turn is a subcategory of Facilities.

The really big problem is to add the spaces - indicated as   in html - in accordance to the subcategory's depth. I tried to build a function but it doesn't work and it only confuses me more and more. I don't wanna post it here because it'll only confuse you as well.

Just remember that I need to display those categories in a DROP DOWN BOX of a form, and the indention is made with  

 

Thanks in advance for any help and sorry for the trouble



-------------
Visit my site: http://darkgreen.service-club.net - DarkGreen HQ



Replies:
Posted By: ziwez0
Date Posted: 22 September 2003 at 12:18pm
have you tried replacing   with &VbCrlf, is this all within one dropdown menu?


Posted By: FLATLINE
Date Posted: 22 September 2003 at 12:22pm

Wouldn't &VbCrlf make a new row? That's not what I need, I need a blank character space.

And yes it's all within one dropdown menu.



-------------
Visit my site: http://darkgreen.service-club.net - DarkGreen HQ


Posted By: FLATLINE
Date Posted: 22 September 2003 at 2:36pm

I think I should ask the simpler question here because I think I'm confusing other people more than myself...

Lets say that I know the integer depth of a subcategory. I use that value to add an appropriate number of   strings to a one global variable. But how can I properly add   spaces and truncuate them back so it'll work with the other subcategories??



-------------
Visit my site: http://darkgreen.service-club.net - DarkGreen HQ


Posted By: Bluefrog
Date Posted: 23 September 2003 at 8:52am
Originally posted by FLATLINE FLATLINE wrote:

Every category has:
cat_id - Unique autonumber of each category
cat_parent - The cat_id of the parent category
cat_name - The display name of the category

  • Animals
    • Rabbits
    • Dogs
    • Cats
  • Facilities
    • Houses
      • Apartment
        • 2-3 Floors
        • 4-12 Floors
        • 12+ Floors
      • Private
    • Factories
    • Other

I've been working on a similar problem for a couple weeks off and on. However, I'm still fiddling around with how I want to model my data...

What I want to do is create a category system where subsets can be supersets of supersets.

From your example (sort of), Facilities could be a subcategory of Factories.

Another example would be:

  • Animals
    • Rabbits
    • Dogs
      • Fleas
        • Filth
          • Government
            • Cockroaches
    • Cats
  • Facilities
    • Houses
      • Apartment
        • 2-3 Floors
        • 4-12 Floors
        • 12+ Floors
      • Private
      • Subsidized Housing
        • Government
          • Corruption
      • Tenants
        • People
          • Drug Addicts
            • Cheech & Chong
          • Crack Whores
            • Cartman's Mother
            • Politicians
              • Government
        • Animals
        • Dogs
        • Cockroaches
          • Filth
            • Government
    • Factories
      • Filth
        • Government
          • Corruption
    • Other
  • Government
    • Corruption
      • Ministry of Lying
        • Ministry of Justice
      • Ministry of Cheating
        • Ministry of Justice
          • Corruption
          • Filth

There is a reason to my madness, as I've clearly illustrated. e.g. Clearly, you will find Filth within the Ministry of Justice, but also where you find Filth, you are also likely to find Government.

Inside of the concept of "Cockroach" you will find the idea "Filth". Inside of the concept "Filth" you will find the concept "Government". Inside of "Government", you will find "Politicians", and all Politicians are Cockroaches.

How to model that though... I've pretty much settled on a second table to handle the "joins".  I'm still fiddling though because something doesn't quite smell right and I can't test it without thousands of entries and extensive testing.

For the display, I'll probably go for some kind of DHTML expanding menu and not a select. But I will at some point need them.

For that, you may want to consider using a "null" character like '-' or '.' or '>'. Selects can be fussy with how they display things.

Find out how many "deep" each record is, then write that many "null" characters.

However, that is a pretty bad idea for a select unless you have a small number of records and they don't go too deep. I'd reconsider how you want to display things. DHTML may be the answer. SoThink has a good editor for that. Just Google "Sothink".

I know for my problem, I will face an infinite number of records "deep" because I can always go Cockroaches --> Filth --> Government --> Cockroaches --> Filth --> Government --> Cockroaches --> Filth --> Government --> Cockroaches --> Filth --> Government, etc.

That's another problem though. I'm pretty sure I have



Posted By: FLATLINE
Date Posted: 23 September 2003 at 11:51am

I see what you want to achieve with your idea, but it's not something that I was planning to do. I wasn't planning to make subcategories which are under multiple other subcategories, my plan was that every subcategory has only 1 parent.

Also, I MUST use a select tag because I need it in a FORM.

I had an idea of how to do it but there's a problem that I have no idea why it's happening:

I thought of making the function which displays the subcategories to recieve 2 paremeters: one will be the parent id number, and the other will be a string that contains the spaces ( ). Then:

<%
Function addsubcat(parentID, strSpaces)

sql = "SELECT * FROM categories WHERE cat_parent = " & parentID & ";"
Set rsCat = Server.Createobject("ADODB.Recodset")
rsCat.open sql, ado

WHILE NOT rsCat.EOF

strNewSpaces = strSpaces & "&nbsp;"

Response.Write("<option value=" & rsCat("cat_id") & ">" & strNewSpaces & rsCat("cat_name") & "</option>")

addsubcat(rsCat("cat_id"), strNewSpaces)
rsCat.MoveNext

WEND
rsCat.close
Set rsCat = Nothing

End Function

%>

This idea should work really well you'd think, but I get a really strange error:

HTTP 500.100 - Internal Server Error - ASP error

Error Type:
Microsoft VBScript compilation (0x800A0414)
Cannot use parentheses when calling a Sub
/*********.asp, line ***, column 37
addsubcat(rsCat("cat_id"), strSpaces)
------------------------------------^

Why doesn't it accept more than one paremeter??



-------------
Visit my site: http://darkgreen.service-club.net - DarkGreen HQ



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net