home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
General Forums
OffTopic
Programming Logic
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="jmhecker" data-source="post: 540404" data-attributes="member: 86959"><p>Okay, so I have a database that is constructed as so:</p><p></p><p>[CODE]CREATE TABLE Categories (</p><p> category_id integer PRIMARY KEY AUTOINCREMENT,</p><p> content_id int,</p><p> parent_category_id int,</p><p> category_name varchar(100),</p><p> pinned int,</p><p> pincode int</p><p>);[/CODE]</p><p></p><p>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: </p><p></p><p>[CODE]SELECT category_id, category_name FROM Categories WHERE parent_category_id=0;[/CODE]</p><p></p><p>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.</p><p></p><p>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.</p><p></p><p>[CODE]SELECT category_id, category_name FROM Categories WHERE parent_category_id=%VAR HERE WITH ID%;[/CODE]</p><p></p><p>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.</p><p></p><p>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.</p><p></p><p>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.</p><p></p><p>Can anyone offer some ideas? Perhaps some pseudo code or something to point me in the right direction?</p></blockquote><p></p>
[QUOTE="jmhecker, post: 540404, member: 86959"] Okay, so I have a database that is constructed as so: [CODE]CREATE TABLE Categories ( category_id integer PRIMARY KEY AUTOINCREMENT, content_id int, parent_category_id int, category_name varchar(100), pinned int, pincode int );[/CODE] 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: [CODE]SELECT category_id, category_name FROM Categories WHERE parent_category_id=0;[/CODE] 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. [CODE]SELECT category_id, category_name FROM Categories WHERE parent_category_id=%VAR HERE WITH ID%;[/CODE] 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? [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
General Forums
OffTopic
Programming Logic
Contact us
RSS
Top
Bottom