473,609 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Category / Sub Category Database Logic *Great minds needed*

9 New Member
Hi everyone,

I'm creating a very powerful web store script in ASP. One of the things I am adding is to allow the user to create their own categories and sub categories for items they wish to sell.

This isn't a new concept or anything but what I'm doing is allowing them to create "Main or Master Categories". An example of a main category would be "Electronic s".

They can now create sub categories under "Electronic s".

If for example they created a sub category under Electronics, labeled "Television s" it would look like this:

Electronics
Televisions

I am also allowing them to now add as many sub categories as they'd like to make it very specific to what they want to display.

They could have Electronics > Televisions > LCD > 32"+ > Vizio

There would be no limit to the amount of sub categories to add.

One problem I am having with the logic is building a hierarchy view in their control panel. I am coding it like this:

In my MySQL database, I have a table named shop_categories

Columns are:

cid
name - name of the categories
level - 0 = master category, 1 - however many are sub categories
parent - the category 1 up from the current
maincat - main category listed under

In this way I am able to see where everything is and which category is linked in a "category relationship".

Creating and saving is always the easy part I know... Grabbing the data and building it back is another problem all together.

Things I want to do:

#1 Display the categories in a tree view style, alphabetically.

#2 Display the categories in an HTML SELECT BOX alphabetically

So for example, #1, If there were main categories Electronics, Automotive, Garden... all with sub categories, it would display:

Automotive
Tires
BF Goodrich
All Season
Firestone

Electronics
Televisions

Garden
Pottery
Clay
Plastic


And for example #2, when I do a For Next loop through the database, the SELECT BOX will be sorted, like in Visual Basic Listbox, you can add items in any order and they sort automatically.


For #1, I was going to do something like:

Query the database and get a record count for how many master categories I have

For x = 0 to RecordCount - 1

Then do another for next loop inside this loop that is looping through the main categories. This secondary loop would get all subcategories for that main category.

For i = 1 to 100

Select name from shop_categories where maincat = recordarray(4,x )

Exit For if no records are returned

----------------------

It would work fine and dandy, however, doing a loop inside of a loop is only capable of getting 1 sub category at a time, since I don't know how many sub categories there will be it can vary from user to user and main category to main category, how can I build this dynamically?

Any advice on the logic to use would be greatly appreciated. I've been going for too many hours straight and I am out of answers to my own brain.

Many Thanks
Nov 25 '08 #1
1 3523
CroCrew
564 Recognized Expert Contributor
Hello TomLasky,

Just to make sure, you want this done in “Classic ASP” development right?

Thanks,
CroCrew~
Dec 1 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

18
4591
by: mountain man | last post by:
Greetings to all database professionals and laymen, Let us make a bold assumption that we have developed a software tool for the SQL Server environment which simply acts as an interface between an end-user in an organization and the database, through the exclusive use of stored procedures which are authored by the organization or by software developers. All development work at the application software level may thereby be conducted...
4
2613
by: Frnak McKenney | last post by:
I'm using an in-core DataSet as an image of my application's 'database' (a multi-table Access97 mdb file). Updates are made to the DataTables within the DataSet via forms with bound TextBoxes, then written to the database... or at least that's what's supposed to be happening. Unfortunately, I've discovered that while it appears that when I create a new record/row I'm successfully updating the Access database, once the Update is...
2
1398
by: Ambassador | last post by:
How can I access server mdb file database by using embedded vb from my handle device. I need a sample code. Thank you My device is PT930 and pt930S.
4
4881
by: Digital Fart | last post by:
howto make a connection to database available in my classes. What is the best practice when i want to write classes that need a connection to the database? Do i make a conn variable in my main() and give it as a parameter to every object i make that needs access to the database ex.
5
2268
by: Red | last post by:
Hi, Can someone give me some pointers on how to approach creating multi level category navigation for a website? Take ebay for example. No matter where you are, you have a navigation bar telling you how you got there, and can click on these to go to any of the parent levels; Music > CDs > Folk > American
35
4828
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection string in the web.config. I created a class with a static database connection and the class opens and closes the database.
0
1324
by: Jim Stools | last post by:
Hopefully this will make some sense.. I have a database that has around 50 tables - I thought about putting each table in a class and the data connection in a class then I could manage the (tables) classes with one data connection. The business logic would open the database class then whatever table class is needed, the close the tables and the connection. The other way would be to open a data connection in each class. Since mutiple...
4
1409
by: Jim Stools | last post by:
Forget the re-post I had my clock set 12 hours earlier Hopefully this will make some sense.. I have a database that has around 50 tables - I thought about putting each table in a class and the data connection in a class then I could manage the (tables) classes with one data connection. The business logic would open the database class then whatever table class is needed, then close the tables and the connection. -- I have may doubts...
4
1910
by: The Facilitator | last post by:
Well, Outlook seems to be making my life more and more challenging. Categories are added in one field and are delimmited via comma. Have three questions on this one... The first is right now my query will only check the first characters in the field to confirm whether they match the original split I did with the other code I showed under VBA breakout (you'll notice I used the code in the part I show here for part two and three of this...
0
8127
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
8067
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,...
0
8527
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8398
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...
0
4015
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...
0
4076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2529
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
1
1658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1380
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.