Jump to content


Photo

How can I display a tree-like categories ?


  • Please log in to reply
3 replies to this topic

#1 mgurain

mgurain
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 August 2004 - 07:34 AM

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,,

#2 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 28 August 2004 - 03:58 PM

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.

#3 mgurain

mgurain
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 August 2004 - 08:34 PM

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,,

#4 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 29 August 2004 - 08:39 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users