showing categories and subcategories

Results 1 to 2 of 2

Thread: showing categories and subcategories

  1. #1
    Join Date
    Dec 1969

    Default showing categories and subcategories

    Hi guys,<BR><BR>I&#039;m trying to write some code which connects to a database, selects all the categories in a table, and then for each category, shows all the subcategories that belong to that parent category.<BR><BR>There is a perfect algorithm which does that at<BR><BR>.. and it only requires one database access (and is capable of showing nested subcategories up to any depth).<BR><BR>However, what I&#039;m trying to do is to modify this code a bit, so that when the subcategories are displayed, to show on the same line which are their parent categories. Here is an example of the structure I want to be displayed:<BR><BR>category1<BR>category2<BR>catego ry2 &#062; subcategory2_1 &#062; subcategory2_1_1<BR>category3<BR>category3 &#062; subcategory3_1<BR>category3 &#062; subcategory3_1 &#062; subcategory3_1_1<BR>category4<BR><BR>... etc.<BR><BR>I have given it a try (mainly by storing each category found in a string and displaying the string when a subcategory is printed) but didn&#039;t manage to make it work.<BR><BR>Any ideas?<BR><BR>Thanks,<BR>nasos<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default This is off the top of my head, but...

    ...maybe just pass the "path" to the category into the function. Something like this:<BR><BR>Function DisplayCategories(aCategories, ByVal iCurID, ByVal iDepth, sPath)<BR>&nbsp;&nbsp;Dim strHTML<BR>&nbsp;&nbsp;strHTML = ""<BR> <BR>&nbsp;&nbsp;Const CategoryID = 0, Name = 1, Link = 2, ParentID = 3<BR> <BR>&nbsp;&nbsp;Dim iNumRecords, iLoop, i<BR>&nbsp;&nbsp;iNumRecords = UBound(aCategories, 2)<BR>&nbsp;&nbsp;For iLoop = 0 to iNumRecords<BR>&nbsp;&nbsp;&nbsp;&nbsp;If CInt(aCategories(ParentID, iLoop)) = CInt(iCurID) then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For i = 1 to iDepth<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;strHTML = strHTML & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"<BR>&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;Next<BR>&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;strHTML = strHTML & "&#060;a href=""" & aCategories(Link, iLoop) & """&#062;" & _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;sPath & aCategories(Name, iLoop) & "&#060;/a&#062;&#060;br /&#062;"<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;strHTML = strHTML & _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;DisplayCategories(aCategories, aCategories(CategoryID,iLoop), iDepth+1, sPath & aCategories(Name, iLoop) & " &#062; ")<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>&nbsp;&nbsp;Next<BR><BR>&nbsp;&nbsp;DisplayC ategories = strHTML <BR>End Function<BR><BR>Well, something like this anyway.<BR><BR>Oliver.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts