I am having an issue with one final piece of logic for an administration app. I’m creating for a search engine. The links within the search engine are categorized (and subcategorized).
The category tree is stored in the database using (what I have found to be called) the recursion method. Tables are as follows:
Table: Category
| Category_Id | | Category|
Table: Category_Subcategory
| Parent_Id | | Child_Id |
Table: Site_Category
| Site_Id | | Category_Id |
I understand that the recursion method is not the best way to store hieratical data, but it is what I currently have, anyway…
In one of the interfaces I need to know if a category (or one of its subcategories) has a site within it, so I know whether to make it a link in the interface. My problem comes in when I try to figure out the logic to use to check for sites. I have written a piece of code which will check the category, and if no site is ‘in’ that category it will then check its subcategories for sites. My problem is that I need a way for the code to continue traveling down the subcategories (of subcategories) until a site is found, or end when there are no other subcategories to check.
Since I want the code to stop as soon as a site is found I figure I need to place the entire code within a while loop, set a variable to 0 and use that variable to check against in the setup of the while loop, but I cannot figure out how to get code to dynamically traverse all the subcategories of a subcategory, since I will have no idea of how many levels of subcategories are within a category.
Ok, just trying to explain the problem has confused me, so if this doesn’t make sense please let me know, and I will try to explain it better.
Any help will be appreciated.
Thanks,
Itshim
The category tree is stored in the database using (what I have found to be called) the recursion method. Tables are as follows:
Table: Category
| Category_Id | | Category|
Table: Category_Subcategory
| Parent_Id | | Child_Id |
Table: Site_Category
| Site_Id | | Category_Id |
I understand that the recursion method is not the best way to store hieratical data, but it is what I currently have, anyway…
In one of the interfaces I need to know if a category (or one of its subcategories) has a site within it, so I know whether to make it a link in the interface. My problem comes in when I try to figure out the logic to use to check for sites. I have written a piece of code which will check the category, and if no site is ‘in’ that category it will then check its subcategories for sites. My problem is that I need a way for the code to continue traveling down the subcategories (of subcategories) until a site is found, or end when there are no other subcategories to check.
Since I want the code to stop as soon as a site is found I figure I need to place the entire code within a while loop, set a variable to 0 and use that variable to check against in the setup of the while loop, but I cannot figure out how to get code to dynamically traverse all the subcategories of a subcategory, since I will have no idea of how many levels of subcategories are within a category.
Ok, just trying to explain the problem has confused me, so if this doesn’t make sense please let me know, and I will try to explain it better.
Any help will be appreciated.
Thanks,
Itshim