Okay, so I have a database that is constructed as so:
That DB will have the names of root and child nodes which will be used to populate a treeview. What will be done is the code will run a query such as this on the DB:
That will grab all of the category information I need (at this point in time) from the DB. It will basically return all of the 'root nodes' for my category tree.
Now that I have the root nodes, I need to use each of those (referencing the category_id) to go through the DB again to select any child nodes.
That works fine...it goes ahead and grabs the listing of child nodes for each root node. But, this is where the trick comes into play.
I once again need to repeat the 2nd SQL statement for each of the child nodes returned the first time I ran the 2nd query...then I need to do it again for the 2nd list returned, and then the 3rd, and the 4th, etc. Depending on the complexity of the tree, I could have to do that hundreds of times per each root node.
I am running into a problem there. I can not seem to logically tackle this without nesting hundreds upon hundreds of for/next, or if/then, or while loops.
Can anyone offer some ideas? Perhaps some pseudo code or something to point me in the right direction?
VB.NET:
CREATE TABLE Categories (
category_id integer PRIMARY KEY AUTOINCREMENT,
content_id int,
parent_category_id int,
category_name varchar(100),
pinned int,
pincode int
);
That DB will have the names of root and child nodes which will be used to populate a treeview. What will be done is the code will run a query such as this on the DB:
VB.NET:
SELECT category_id, category_name FROM Categories WHERE parent_category_id=0;
That will grab all of the category information I need (at this point in time) from the DB. It will basically return all of the 'root nodes' for my category tree.
Now that I have the root nodes, I need to use each of those (referencing the category_id) to go through the DB again to select any child nodes.
VB.NET:
SELECT category_id, category_name FROM Categories WHERE parent_category_id=%VAR HERE WITH ID%;
That works fine...it goes ahead and grabs the listing of child nodes for each root node. But, this is where the trick comes into play.
I once again need to repeat the 2nd SQL statement for each of the child nodes returned the first time I ran the 2nd query...then I need to do it again for the 2nd list returned, and then the 3rd, and the 4th, etc. Depending on the complexity of the tree, I could have to do that hundreds of times per each root node.
I am running into a problem there. I can not seem to logically tackle this without nesting hundreds upon hundreds of for/next, or if/then, or while loops.
Can anyone offer some ideas? Perhaps some pseudo code or something to point me in the right direction?