473,320 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dynamic catalog with unlimited category levels?

Hey,

I've done a number of product catalogs/galleries with one or two
category levels (Category > Subcategory). The straightforward way to do
this, of course, is to use database fields for Category and Subcategory
and query off of those fields.

I have a client now who is interested in what sounds to me to be an
unnecessarily complex catalog with an as of yet undefined number of
category levels at their disposal.

My initial response would be just to add more levels of subcategories to
the database, but I was wondering if anyone had come up with a system
allowing the dynamic addition of an unlimited number of subcategories to
a catalog, and would be willing to share your methods. Or, if I should
just stick to the obvious plan.

Thanks.
Jul 19 '05 #1
5 3360
Hi

You're correct to ask. I think you're looking for 'recursion'.

One table:

CategoryID, ParentCategoryID, CategoryName

Parent categories will have a ParentCategoryID of zero.

So, to get the top level you say, SELECT CategoryID, Category FROM
tblCategories WHERE ParentCategoryID = 0

If you were looking to build up some sort of tree view where all the
categories can be navigated, you would need two queries. One as above, to
get the top level and then another one that returns the whole table without
the top level categories. Use GetRows to put the results in to an array and
then use something like this to draw it out. Paste this lot in to Notepad
to make more legible. (Have another field which tells me if there are any
subcategories/replies, this is taken from some Forum code.)

Post back if you need more, or I could email the whole page.

Regards

David
'--- Start Snippet

<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th colspan="2"><img border="0" src="../images/1px.gif" WIDTH="1"
HEIGHT="1"></th>
</tr><% For i = 0 To iTopics %>
<tr <%=AlternateRow(i)%>>
<td class="Padded" valign="top"><img border="0" src="../images/1px.gif"
WIDTH="1" HEIGHT="2"><br><%
If arrTopics(5, i) Then ' HasReplies %>
<a href="javascript:toggleMessage(<%=arrTopics(0, i)%>)"><img
id="img_<%=arrTopics(0, i)%>" name="img_<%=arrTopics(0, i)%>" border="0"
src="images/Plus.gif" WIDTH="10" HEIGHT="10"></a><%
End If %></td>
<td class="Padded" valign="top"><span class="<%=IsRead(i)%>"
id="spn<%=arrTopics(0, i)%>"><a href="javascript:vM(<%=arrTopics(0,
i)%>)"><%=Server.HTMLEncode(arrTopics(2, i))%></a></span>
<%=FormatDateTime(arrTopics(3, i), vbShortDate) & " " &
FormatDateTime(arrTopics(3, i), vbShortTime) & " " &
Server.HTMLEncode(arrTopics(4, i))%><%
If arrTopics(5, i) Then ' HasReplies %>
<table id="tblReplies_<%=arrTopics(0, i)%>" cellpadding="0"
cellspacing="0" border="0" class="Hidden">
<tr>
<td><%=BuildThreads(arrMessages, arrTopics(0, i), 0)%></td>
</tr>
</table><%
End If %></td>
</tr>
<tr>
<th colspan="2"><img border="0" src="../images/1px.gif" WIDTH="1"
HEIGHT="1"></th>
</tr><% Next %>
</table><% End If %>
</body><SCRIPT LANGUAGE=javascript>
<!--

//-->
</SCRIPT>
</html>
<SCRIPT LANGUAGE=vbscript RUNAT=Server>
Function BuildThreads(vMessages, ByVal vCurrentTopicID, ByVal vDepth)
If Not bHasMessages Then Exit Function
Dim stThreads, i
For i = 0 to iMessages
If vMessages(1, i) = vCurrentTopicID Then
stThreads = stThreads & "<table style=""padding-top: 5px"" border=""0""
cellpadding=""0"" cellspacing=""0""><tr><td valign=""top""><img border=0
src=""../images/1px.gif"" WIDTH=12 HEIGHT=2><br>"
If vMessages(5, i) Then
stThreads = stThreads & "<a href=""javascript:toggleMessage(" &
vMessages(0, i) & ")""><img id=""img_" & vMessages(0, i) & """ name=""img_"
& vMessages(0, i) & """ border=""0"" src=""images/Plus.gif"" WIDTH=""10""
HEIGHT=""10""></a>"
End If
stThreads = stThreads & "</td><td valign=""top""><span id=""spn" &
vMessages(0, i) & """ class=""" & IsRead2(i) & """><a href=""javascript:vM("
& vMessages(0, i) & ")"">" & _
Server.HTMLEncode(vMessages(2, i)) & "</a></span> " & _
FormatDateTime(vMessages(3, i), vbShortDate) & " " &
FormatDateTime(vMessages(3, i), vbShortTime) & " " & _
Server.HTMLEncode(vMessages(4, i))
If vMessages(5, i) Then
stThreads = stThreads & "<table id=""tblReplies_" & vMessages(0, i) &
""" class=""Hidden""><tr><td>" & _
BuildThreads(vMessages, vMessages(0, i), vDepth +1) & _
"</td></tr></table>"
End If
stThreads = stThreads & "</td></tr></table>"
End If
Next
BuildThreads = stThreads
End Function
'--- End Snippet

"Travis Pupkin" <tp*****@dorrk.com> wrote in message
news:MP************************@news.individual.ne t...
Hey,

I've done a number of product catalogs/galleries with one or two
category levels (Category > Subcategory). The straightforward way to do
this, of course, is to use database fields for Category and Subcategory
and query off of those fields.

I have a client now who is interested in what sounds to me to be an
unnecessarily complex catalog with an as of yet undefined number of
category levels at their disposal.

My initial response would be just to add more levels of subcategories to
the database, but I was wondering if anyone had come up with a system
allowing the dynamic addition of an unlimited number of subcategories to
a catalog, and would be willing to share your methods. Or, if I should
just stick to the obvious plan.

Thanks.

Jul 19 '05 #2
Travis Pupkin <tp*****@dorrk.com> wrote in message news:<MP************************@news.individual.n et>...
Hey,

I've done a number of product catalogs/galleries with one or two
category levels (Category > Subcategory). The straightforward way to do
this, of course, is to use database fields for Category and Subcategory
and query off of those fields.

I have a client now who is interested in what sounds to me to be an
unnecessarily complex catalog with an as of yet undefined number of
category levels at their disposal.

My initial response would be just to add more levels of subcategories to
the database, but I was wondering if anyone had come up with a system
allowing the dynamic addition of an unlimited number of subcategories to
a catalog, and would be willing to share your methods. Or, if I should
just stick to the obvious plan.

Thanks.


Seems to me you'd have a category table with the following columns

category_id
parent_category_id
description

Then each item in the catalog would point to the category_id

The maintenance for each sub-category would be simple, as one would
pick the parent category when adding a sub category.
Jul 19 '05 #3
>
Seems to me you'd have a category table with the following columns

category_id
parent_category_id
description

Then each item in the catalog would point to the category_id

Thanks; I think I wasn't clear in my question. The table for the
categories/subcategories is not so much of a brain-buster for me, but
the method with which I assign items to the cats/subcats is. I've been
trying to thing if there's a better way to do it than having, say, 5
designated fields in the main db table like:

CategoryID
subcat01ID
subcat02ID
subcat03ID
subcat04ID

....limiting it to One parent category and 4 subcategories. This client
doesn't know yet how deep they want their subcats to go for an item, so
I'm trying to think ahead for them.

I was more curious if someone had found a way to design a totally
flexible category system that allows for unlimited assignations of
category levels to an individual item?

I think probably not, but my realm of knowledge is very narrow, and
asking helps me procrastinate programming.
Jul 19 '05 #4
I think everyone had your answer

ONE TABLE

CategoryID, ParentCategoryID

That's all you need for unlimited levels.

How you extract the hierarchy is the challenge, which is what my recursive
function accomplishes.
"Travis Pupkin" <tp*****@dorrk.com> wrote in message
news:MP************************@news.individual.ne t...

Seems to me you'd have a category table with the following columns

category_id
parent_category_id
description

Then each item in the catalog would point to the category_id

Thanks; I think I wasn't clear in my question. The table for the
categories/subcategories is not so much of a brain-buster for me, but
the method with which I assign items to the cats/subcats is. I've been
trying to thing if there's a better way to do it than having, say, 5
designated fields in the main db table like:

CategoryID
subcat01ID
subcat02ID
subcat03ID
subcat04ID

...limiting it to One parent category and 4 subcategories. This client
doesn't know yet how deep they want their subcats to go for an item, so
I'm trying to think ahead for them.

I was more curious if someone had found a way to design a totally
flexible category system that allows for unlimited assignations of
category levels to an individual item?

I think probably not, but my realm of knowledge is very narrow, and
asking helps me procrastinate programming.

Jul 19 '05 #5
Are you saying that the issue is not in the category tables but that you
want to assign a single row in another table (call it "products") to more
than one category (ie: product "book" could be in categories "children",
"science" , and "non-fiction")?

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Travis Pupkin" <tp*****@dorrk.com> wrote in message
news:MP************************@news.individual.ne t...

Seems to me you'd have a category table with the following columns

category_id
parent_category_id
description

Then each item in the catalog would point to the category_id

Thanks; I think I wasn't clear in my question. The table for the
categories/subcategories is not so much of a brain-buster for me, but
the method with which I assign items to the cats/subcats is. I've been
trying to thing if there's a better way to do it than having, say, 5
designated fields in the main db table like:

CategoryID
subcat01ID
subcat02ID
subcat03ID
subcat04ID

...limiting it to One parent category and 4 subcategories. This client
doesn't know yet how deep they want their subcats to go for an item, so
I'm trying to think ahead for them.

I was more curious if someone had found a way to design a totally
flexible category system that allows for unlimited assignations of
category levels to an individual item?

I think probably not, but my realm of knowledge is very narrow, and
asking helps me procrastinate programming.

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Troy Lynch | last post by:
I'm working on writing a website which I need to have lists of products listed in categories and subcategories, and need to keep track of whats in the tree. Like how many products from the root all...
2
by: Angelos | last post by:
Hello there... I am trying for a long time now, to find a way of creating a dynamic drop down menu. I have the CSS part ready and working and also I have the first level of the menu working. the...
2
by: Jefferis NoSpamme | last post by:
I am looking at an old query and I cannot remember or figure out what this part of the query means: `Catalog`.item like '%A\-%' It is the like '%A\-%' I cannot figure out. Then entire...
3
by: Angelos | last post by:
Hello there, I am trying to write a script that will create dynamically a menu from MySQL database. The database table is a product categories table and it has the folowing filed: category_id,...
1
by: Øyvind Isaksen | last post by:
Hello! I have a MSSQL 2003 database that stores the menu structure (categories) for my webpage. The category table consist of categoryID, category Name and parentID (parentID is the ID of the...
19
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
2
by: sandeep.manthena | last post by:
Hi everyone, Can anyone answers my questions. My server is AIX and is 5.2 and the db2 udb of V 8.1 Fixpak 9. What exactly is the tools catalog for? How it is uaseful in performing automatic...
0
by: Al2000 | last post by:
Hi I'm looking for a php based payment management with a catalog. Payment side has to have option to pay in installments, like on a schedule, charge for late payment based on a preset formula,...
3
by: jaddi1 | last post by:
Hi, I am trying to make a multi-level drop-down menu similar to what is seen here: http://www.cssplay.co.uk/menus/simple_vertical.html. My problem is that some of the menu will be populated from...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.