Dynamically building categories - where to start?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lyndonw
Forum Newbie
Posts: 1
Joined: Sat Apr 02, 2005 8:28 am

Dynamically building categories - where to start?

Post by lyndonw »

Hi

Im after some help because I can't figure out the best way to go about this.

I have 2 tables in a database, products and category_map.

In the product table is a comma seperated field for the categories (i.e. 234,345,567 - for multiple category entries).

I have seperated these using explode, but what I want to do is build a category list based on the names in the category_map field which relate to the numeric values in the product table. The category_map already holds the numeric values.

To complicate things the category_map has 3 fields, id, descr, and mastid.

id = the numeric value as in the products table
descr = description
mastid = master category id (for child categories)

Any and all pointers/tutorial links/code snippets would be most welcome.

Thanks in advance.

Lyndon
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I would rebuild this comma seperated field into a seperate table you can JOIN your selection with. The major reason why is this situation, and your future database state. Imagine you have millions of categories. A "newer" (higher ordinal number) category will greatly limits the number of other categories you can attach with that product than if the product is apart of the "older" (lower ordinal number) categories.

The following may be of help http://www.oreilly.com/catalog/javadtab ... r/ch02.pdf
Post Reply