A drop-down box has a list of all the "product categories" and it also shows all the children each "product category" has. Unfortuently the d/d box is way too long and is very confusing.
What I'm trying to do is cut down the number of items in the d/down list and repetitive SQL queries. In order to do this I need to do a SQL query to count how many childs a parent category has.
The table structure is thus;
So, this would mean having to do a recursive SQL query to go through this table to find out how many childs a parent category has.Code:# Pseduocode table product_category { var id (primary key) var parent_id (secondary key) var name (the name of the category) } #@end:table
Currently we use a php function and it recursively loads the function and spits out all the data, some of which is totally unnecessary.. All I need is the ultimate child of a parent (or where there is no more children) and return the COUNT variable.
Is there a way to do this? I'm thinking it would be an inner join on itself? Is this right?
I hope you can help.
Thanks.








Bookmarks