473,786 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help w/ Unlimited depth categories

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
the way down through the subcategories. I was thinking maybe in each
category it would have a field which lists all the root categories. I
hope this is a good explanation... it's kinda hard to explain I guess.
I figure there were probably some websites out there with methods or
something... Any help on this would be great.... Or a direction I can
do some researching..

Thanks

Troy
Jul 17 '05 #1
2 3527
Hi Troy!

On 4 Jan 2004 16:18:16 -0800, dj********@yaho o.com (Troy Lynch) wrote:
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
the way down through the subcategories. I was thinking maybe in each
category it would have a field which lists all the root categories. I
hope this is a good explanation... it's kinda hard to explain I guess.
I figure there were probably some websites out there with methods or
something... Any help on this would be great.... Or a direction I can
do some researching..


There should be heaps. Have a search for "tree php adjacent" or "tree
php nested set". These are the two most common methods.

HTH, Jochen
--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #2
Greetings.

One possibility is to have a field like "mother_categor y" in the
categories list. Each category would have a "mother", referred by it's
record ID or something like that. The category with mother_category =0
would be the root.

To count the products in a branch, create a recursive function that
adds the produtcs in every sub-category of the category you want to
start.

Something like:
Table categories:
id
category
mother_category <- categories.id

Table products:
id
cat_id <- categories.id
product

The function:
Parameter: top_id (id of the top category you want to consider)
How it works:
count the number of products with cat_id = top_id;
get the list of the sub-categories of the top_id category;
for each sub-category, it calls itself and adds the result to the
sum of products
Returns: the sum of products of that branch

Hope this helps,
Joaquim Amado Lopes

Jul 17 '05 #3

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

Similar topics

0
2252
by: Brian Murphy | last post by:
<?php /* I need your help. I'd be very thankfull if write me this script.I need a script that displays a list of categories and subcategories like this: <select name="category"> <option value="1">Main</option> <option value="2">Main > Computers</option> <option value="4">Main > Computers > Hardware </option>
1
1707
by: Bola | last post by:
Hi there. U have table structure shown here: category (Int - AutoIncrement) parent_category(Int) Title(string) 1 0 HOME PAGE 2 1 FIRST DEPTH 1 3 1 FIRST DEPTH 2 4 1
5
3385
by: Travis Pupkin | last post by:
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.
4
3467
by: Jani Yusef | last post by:
I want to create a tree of processes. The depth of the tree is given by the variable depth and the number of processes started by each node is given by the variable numberOfProcesses. Is the following code correct? I don't think it is, especially since I don't want the bottom nodes(leaf nodes) to start any processes themselves. Any comments on the following code would be much appreciated!! for(j=0;j<depth;j++){...
4
1652
by: Steve Klett | last post by:
(I posted this in ADO group, but I think this group will be better) Hi- I need to develop an FAQ section for our website. We would like to break up the FAQ by products, then categories with each category having n question/answer pairs. I would like to pass parameters in the querystring based on what the product/category the user selected, then populate a datagrid with the correct set of question/answer
2
2212
by: tagnum | last post by:
I have written a program for unlimited categories depth, which is in use for few ecommerce websites. Like many others, I used one SQL table to store the category relation (or the tree structure). E.g. child_id & parent_id. To cope with the "unlimited" nature, the htaccess file & html ul list are generated on the fly. To sum it up, it has SEO friendly URLs, breadcrumbs, CSS driven navigation bar, category ordering in the backend, etc. But I...
25
2096
by: vikram Bhuskute | last post by:
I have plans to train some students for C in coming weeks. I am badly looking for C programming assignments fot them. Need 1) lots of them per topiic 2) Should be doable for beginners thanks in advance Vikram
2
1754
klarae99
by: klarae99 | last post by:
Hello, I am working in Access 2003 on an inventory database. Right now I am working on a report which will be used to fill in forms that our state requires periodically to collect taxes. Right now I have a query that determines the items that have sold between two dates and calculates the Gross Sales, Tax Collected and Sales Including Tax. This query is set up with the following SQL: SELECT tblCat.Categories, tblCat.TaxRate,...
9
2637
by: pereges | last post by:
Hello I need some ideas for designing a recursive function for my ray tracing program. The idea behind ray tracing is to follow the electromagnetic rays from the source, as they hit the object.The object is triangulated. The rays can undergo multiple reflections, diffractions etc of the same object i.e. a ray hits a surface of the object, undergoes reflection resulting in a reflected ray which can again hit a surface, corner or edge...
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.