Jump to content

Archived

This topic is now archived and is closed to further replies.

mgurain

How can I display a tree-like categories ?

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.