I'm using a database combined of several tables, mostly categories and products.
Just added "breadcrumb" style to web pages
i.e. Home > FirstCatgory > SubCategory > Product Name
The code used is below. It works great.
3 tables are used for this working setup
products = includes products names and ID's
categories = includes categories names, IDs and relationship (category, parent category, has-subcategory =yes/null)
prodcategories = id (index), catalogid (product id), categoryid (all category id where it fits in).
Problem:
Many items belong in more than only one subcategory.
The current function would only show the first.
I added it ORDER BY (categories.hassubcategory) so it picks the first category that has no subcategory (bottom of list). That's a partial solution only, as it shows only one option.
Question:
How do I develop the syntex to get the list of all categories (where has_subcategories<>"yes") that are included in prodcategories and output their structure via a loop.
Any help would be greatly appreciated
Just added "breadcrumb" style to web pages
i.e. Home > FirstCatgory > SubCategory > Product Name
The code used is below. It works great.
Code:
function BreadCrumbs(dbc,startcatid,product)
'' ----- DECLARE LOCAL VARIABLES -----
dim cathead ' final output string
dim rs ' record set object for holding contents of the record
dim sql
dim catname ' name of the current category
dim catid ' which category record is currently being processed
dim i ' general purpose iterator
dim mylink ' the link that is generated for the category
if product=true then ' if we are already on an item page then we:
' (a) don't want the product name to be a link, and
' (b) specify which [b]category[/b] the product is from
sql="SELECT products.cname, categories.categoryid FROM [red]categories[/red] "
sql=sql & "INNER JOIN ([red]products[/red] "
sql=sql & "INNER JOIN [red]prodcategories[/red] ON "
sql=sql & "products.catalogid = prodcategories.intcatalogid) "
sql=sql & "ON categories.categoryid = prodcategories.intcategoryid "
sql=sql & "WHERE products.catalogid=" & startcatid
sql=sql & " ORDER BY (categories.hassubcategory)"
set rs=dbc.execute (sql)
cathead=rs("cname")
catid=rs("categoryid")
Closerecordset rs
else
cathead=""
catid = startcatid
End if
'' ----- GET ALL CATEGORIES AND BUILD THE RETURN STRING -----
Do while catid <> 0
Set rs=dbc.execute("select * from categories where categoryid=" & catid)
If not rs.eof Then
strsubcat=rs("hassubcategory")
if isNULL(strsubcat) then strsubcat=""
catname=rs("catdescription")
if catid = startcatid then ' case where it's a product name
mylink=catname
else
if strsubcat<>"" then ' case where it's a root category
mylink="<a href='" & siteurl & "topcat.asp?id=" & catid & "&cat=" & Server.URLEncode(catname) & ">" & catname & "</a>"
else ' case where it's a category with only products in it
mylink="<a href='" & siteurl & "productspage.asp?id=" & catid & "&cat=" & Server.URLEncode(catname) & ">" & catname & "</a>"
end if
end if
If catid = startcatid Then
cathead = mylink
Else
cathead = mylink & " > " & cathead 'separator
End If
catid = rs("highercategoryid")
Else
Closerecordset rs
Exit Do
End If
Closerecordset rs
Loop
BreadCrumbs = " <small> <a href='" & mainurl & "'>Directory</a> > " & cathead & " </small> "
end function
3 tables are used for this working setup
products = includes products names and ID's
categories = includes categories names, IDs and relationship (category, parent category, has-subcategory =yes/null)
prodcategories = id (index), catalogid (product id), categoryid (all category id where it fits in).
Problem:
Many items belong in more than only one subcategory.
The current function would only show the first.
I added it ORDER BY (categories.hassubcategory) so it picks the first category that has no subcategory (bottom of list). That's a partial solution only, as it shows only one option.
Question:
How do I develop the syntex to get the list of all categories (where has_subcategories<>"yes") that are included in prodcategories and output their structure via a loop.
Any help would be greatly appreciated