Welcome Guest, Not a member yet? Register   Sign In
Displaying DB query result in a "tree"?
#1

[eluser]Been Told[/eluser]
Hi everyone,
I'm a complete noob with CI and not THAT advanced with MySQL / PHP (writing my first proper script right now). I'm using CI 1.7.2 on Apache with PHP 5.2 on Ubuntu.

Okay, here is my problem.
I have a DB table with categories.

You can see in this "flowchart", how the categories are organized. Note that lines with arrows represent a parent/child relationship, whereas lines without arrows represent a sibling relationship.

Now I've been trying to figure out a way to display them in a tree and I just can't figure out how to do it.

At first I thought I'd do this:
Give the main categories an id of 1 and 2 respectively.

Then sort all other categories by parent_id and that way seperate them. But that's not possible, because some categories have a parent category which itself is a child of one of the main categories.
So their parent_id will not be 1 or 2, but 4 or 5.

And that's where it gets a little too complicated for my limited skills.

Can anyone help me out here? Maybe just point me in the right direction? Maybe there's a tutorial somewhere or something?
#2

[eluser]WanWizard[/eluser]
Check out Nested_sets in the Wiki.
#3

[eluser]Been Told[/eluser]
That looks like exactly what I need. Thanks very much WanWizard!!! Smile




Theme © iAndrew 2016 - Forum software by © MyBB