Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 think of a function for this?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

redbrad0
Advanced Member

USA
3725 Posts

Posted - 11 July 2001 :  09:57:28  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
ok this is kind of complicated to explain. I have two tables... Categorys and Products. This is the way the tables are setup in the database...

Categorys
Category_ID | Category_Name | Category_Parent_Category
------------------------------------------------------
1 | Root | 1
2 | DVD's | 1
3 | VHS | 1
4 | Comedy | 2
5 | Action | 2
6 | New Release | 4
7 | Old Releases | 4
8 | New Release | 5
9 | Old Releases | 5



Products
Product_ID | Product_Category_ID | Product_Name
-----------------------------------------------
1 | 6 | Big Momma's House
2 | 7 | Bowfinger



So this is the way the direcotry would be laid out..

Root
DVD's
Comedy
New Release
Big Momma's House
Old Releases
Bowfinger
Action
New Release
Old Releases
VHS



Now what I need is a way to Search all the categorys to see if it has any products listed in it and return either true or false. So it would start at the Root Category's and then check if it has any products in it, if it does not, it looks for any categorys then checks those categorys if they have any products, if it doesnt it sees if it has any sub categorys and keeps going like that.

Hopefully I made since and someone can help me. Let me know if you dont understand

Brad

tilttek
Junior Member

Canada
333 Posts

Posted - 11 July 2001 :  11:22:45  Show Profile  Visit tilttek's Homepage
First change this:
quote:

Categorys
Category_ID | Category_Name | Category_Parent_Category
------------------------------------------------------
1 | Root | 0
2 | DVD's | 1
3 | VHS | 1
4 | Comedy | 2
5 | Action | 2
6 | New Release | 4
7 | Old Releases | 4
8 | New Release | 5
9 | Old Releases | 5




quote:

Root
DVD's
Comedy
New Release
Big Momma's House
Old Releases
Bowfinger
Action
New Release
Old Releases
VHS




Then do a recursive function. Here some pseudocode to help you:

Function Search(Categ)
"SELECT * FROM Categorys WHERE Category_Parent_Category = " & Categ
LOOP
WRITE Category_Name
Search(Category_ID)
END LOOP
End Function


It's simple code, not complete, but I know you will be able to do it.

Philippe Gamache
http://www.tilttek.com
http://www.lapageamelkor.com

Edited by - tilttek on 11 July 2001 11:23:43
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 11 July 2001 :  12:44:13  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
quote:


Function Search(Categ)
"SELECT * FROM Categorys WHERE Category_Parent_Category = " & Categ
LOOP
WRITE Category_Name
Search(Category_ID)
END LOOP
End Function




but how will this find out if it has any products in the category?

Brad
Go to Top of Page

big9erfan
Average Member

540 Posts

Posted - 11 July 2001 :  12:50:01  Show Profile
Do that for each DISTINCT Product_Category_ID that you have in your table.

That way for all the categorys that have not been called through that function have not been set up and thus don't have any products.

http://www.ugfl.net/forums
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000 Version 3.4.07