mgurain Posted August 28, 2004 Share Posted August 28, 2004 Hi all,, I have designed my DB to allow tree-like categories (like windows folders), by having two tables : Cats : >>> CatID >>> CatName >>> CatDesc subCats : >>> subCatID >>> subCatName >>> subCatDesc >>> subCatParentID (fk: CatID) >>> subCatLevel but the problem is in displaying the tree ?! it seems that I need SQL statment inside another SQL statment !! I mean for each Cat (SELECT * FROM Cats) I need (SELECT * FROM subCats WHERE subCatParentID = CatID) ! anybody ? thanks in advance,, Quote Link to comment https://forums.phpfreaks.com/topic/1939-how-can-i-display-a-tree-like-categories/ Share on other sites More sharing options...
morpheus.100 Posted August 28, 2004 Share Posted August 28, 2004 Use either a recursive loop to output data or you can nest repeated regions within dreamweaver despite what all the web pages say. Create your main query for the categories and leave the mysql_free-result line where the program inserts it at the page footer. Create another query to get your sub categories = to the identifier (subCatParentID) from your first query. Move the recordset and any other code to be output within the the first recordset along with the appropriate mysql_free_result line and the results should recurse. Quote Link to comment https://forums.phpfreaks.com/topic/1939-how-can-i-display-a-tree-like-categories/#findComment-6307 Share on other sites More sharing options...
mgurain Posted August 28, 2004 Author Share Posted August 28, 2004 Hi morpheus.100,, thanks for your quick reply. Can you please write me a sample code of one of the two methods (or both) ? thanks in advance,, Quote Link to comment https://forums.phpfreaks.com/topic/1939-how-can-i-display-a-tree-like-categories/#findComment-6311 Share on other sites More sharing options...
morpheus.100 Posted August 29, 2004 Share Posted August 29, 2004 Just use 2 standard recordsets. One for the parents and one for the childs. Ensure the child recordset is fully nested within the parent recordset along with any HTML code you wish to output for the child menu. Its a simple copy and paste procedure. Connection Recordset 1 Code to output ~~~~~~~~~~~~~~~~~~~ Recordset 2 Nested code to output for child mysql_free-result(Recordset 2) ~~~~~~~~~~~~~~~~~~~ Any furtheer code to output for Recordset 1(ie</td> etc) mysql_free_result(Recordset 1) If I give code you will never learn. You have to experiment, and that way you will find out just how things can be done. Quote Link to comment https://forums.phpfreaks.com/topic/1939-how-can-i-display-a-tree-like-categories/#findComment-6312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.