Author Topic: How can I display a tree-like categories ?  (Read 1442 times)

0 Members and 1 Guest are viewing this topic.

Offline mgurainTopic starter

  • Irregular
  • Posts: 5
    • View Profile
How can I display a tree-like categories ?
« on: August 28, 2004, 03:34:53 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,,

Offline morpheus.100

  • Enthusiast
  • Posts: 238
    • View Profile
How can I display a tree-like categories ?
« Reply #1 on: August 28, 2004, 11:58:31 AM »
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.

Offline mgurainTopic starter

  • Irregular
  • Posts: 5
    • View Profile
How can I display a tree-like categories ?
« Reply #2 on: August 28, 2004, 04:34:47 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,,

Offline morpheus.100

  • Enthusiast
  • Posts: 238
    • View Profile
How can I display a tree-like categories ?
« Reply #3 on: August 29, 2004, 04:39:11 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.