That's not enough information to build a tree with left and right id's, you'll need to know the relationship between all forums.Dog Cow wrote:They're for sub-forums, right? So you know what the parent forum is, and what the child forum is.
This is my assumption, anyway.
what does left_id and right_id in the table forums?
Forum rules
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Re: what does left_id and right_id in the table forums?
Re: what does left_id and right_id in the table forums?
No, I believe you are mistaken. From what I know from reading the tutorial posted earlier in this topic, the entire tree can be built using just left and right ID's. They are the relationship between the forums.ElbertF wrote:That's not enough information to build a tree with left and right id's, you'll need to know the relationship between all forums.Dog Cow wrote:They're for sub-forums, right? So you know what the parent forum is, and what the child forum is.
This is my assumption, anyway.
Re: what does left_id and right_id in the table forums?
god0fgod wrote:Can anyone please tell me how I would make the numbers for these columns?
I believe godOfgod was asking how to calculate a left and right id for a new forum, in that case you need to know the relationship between all forums and not just the parent of that specific forum. I might be wrong.Dog Cow wrote:They're for sub-forums, right? So you know what the parent forum is, and what the child forum is.
-
- Registered User
- Posts: 66
- Joined: Sun Oct 10, 2004 3:21 am
- Location: Munich (Germany)
- Contact:
Re: what does left_id and right_id in the table forums?
Not quite, you still need the information about the parent. However, using parent_id, left_id and right_id the tree can be built without problems.Dog Cow wrote:No, I believe you are mistaken. From what I know from reading the tutorial posted earlier in this topic, the entire tree can be built using just left and right ID's. They are the relationship between the forums.
Greetz
alcaeus
Re: what does left_id and right_id in the table forums?
First note that nowhere have I said 'rebuilt'. I read the Site Point tutorial, and I understand that the parent is needed to be known for recalculating the left and right id's.
Second note: @ ElbertF, I wasn't answering god0fgod's question, I was answering the topic starter's very first question, since reading through the replies, it seemed to me that no one had provided a clear answer.
Third note: However, to simply 'build' or perhaps I should have said 'display' the tree, only the left and right id's are needed.
Here's a link to the SitePoint article again: http://www.sitepoint.com/print/hierarch ... a-database.
Second note: @ ElbertF, I wasn't answering god0fgod's question, I was answering the topic starter's very first question, since reading through the replies, it seemed to me that no one had provided a clear answer.
Third note: However, to simply 'build' or perhaps I should have said 'display' the tree, only the left and right id's are needed.
Here's a link to the SitePoint article again: http://www.sitepoint.com/print/hierarch ... a-database.
-
- Registered User
- Posts: 66
- Joined: Sun Oct 10, 2004 3:21 am
- Location: Munich (Germany)
- Contact:
Re: what does left_id and right_id in the table forums?
Still not quite. If you want to know the indentation of an element you need to know the parent_id in order to correctly establish the parent and thus the indentation of a child. The left_id is useful to get the children in the right order (thus enabling you to get them with a single simple database query), but if you want to show a tree structure and not simply an ordered list, you need the parent.Dog Cow wrote:Third note: However, to simply 'build' or perhaps I should have said 'display' the tree, only the left and right id's are needed.
Greetz
alcaeus
Re: what does left_id and right_id in the table forums?
The parent_id is not actually needed, only the parent has to be known - and this is also possible without the parent_id (the tree is build solely on left/right ids and if layed out correctly you are able to identify all parents by going through the list and spotting every direct parent from the child on).
But the parent_id is perfect for simplifying the queries a lot and gives better performance - who wants to parse a complete tree to spot the parent(s).
But the parent_id is perfect for simplifying the queries a lot and gives better performance - who wants to parse a complete tree to spot the parent(s).
-
- Registered User
- Posts: 66
- Joined: Sun Oct 10, 2004 3:21 am
- Location: Munich (Germany)
- Contact:
Re: what does left_id and right_id in the table forums?
Could you elaborate? It somehow makes sense, but I'm not able to completely see it. I know you could just query the database and find the forum with the highest left_id that has a left_id less than the childs left_id and viceversa for the right_id, but is there a way to actually do it when looping the result set?Acyd Burn wrote:The parent_id is not actually needed, only the parent has to be known - and this is also possible without the parent_id (the tree is build solely on left/right ids and if layed out correctly you are able to identify all parents by going through the list and spotting every direct parent from the child on).
Greetz
alcaeus
Re: what does left_id and right_id in the table forums?
I've never tried, it has to be determined by code logic (i would bet on a recursive function ) - therefore the "per-se standard" to use a parent id (because a child is only able to have one parent). Since childs left/right ids are always lower than it's parent you are able to query the parent by looking for the nearest left/right id pair higher than the childs.alcaeus wrote:Could you elaborate? It somehow makes sense, but I'm not able to completely see it. I know you could just query the database and find the forum with the highest left_id that has a left_id less than the childs left_id and viceversa for the right_id, but is there a way to actually do it when looping the result set?Acyd Burn wrote:The parent_id is not actually needed, only the parent has to be known - and this is also possible without the parent_id (the tree is build solely on left/right ids and if layed out correctly you are able to identify all parents by going through the list and spotting every direct parent from the child on).
Without having looked at the code... imagine this structure (1 forum, having 2 subforums where the first is having one subforum and the second having 2)
Code: Select all
1 12
| |
--| |---------------
2 5 ----------- 6 11
| |
---| --|------|
3 4 7 8 9 10
Now, imagine you want to find out the direct parent of 9/10... you would search for the nearest left/right id... you would be able to collect all parents first by doing WHERE left_id < 9 AND right_id > 10. Now, you need to "calculate" this resultset again... and so on...
-
- Registered User
- Posts: 66
- Joined: Sun Oct 10, 2004 3:21 am
- Location: Munich (Germany)
- Contact:
Re: what does left_id and right_id in the table forums?
Ok, then I was thinking the same way you did, thanks
Greetz
alcaeus
Greetz
alcaeus