Jump to content

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

Link to comment
https://forums.phpfreaks.com/topic/1939-how-can-i-display-a-tree-like-categories/
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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.