
- You are not logged in. | Login
December 20, 2006 12:18 pm
- admin
- Administrator


Discuss article: "Tree-type structures storage in the database"
We suggest you to discuss that article here
Discussed article: "Tree-type structures storage in the database"
April 12, 2007 8:51 am
- Mr.SMart
- Member


Re: Discuss article: "Tree-type structures storage in the database"
Hmm... Why? How about such a scheme:
cid
cparent
clevel
cpath
where clevel is level in the tree, cparent is parent's cid and cpath is formed in such a way:
cid name clevel cparent cpath
001 Element 1 1 0 001000000
002 Element 2 2 1 001002000
003 Element 3 2 1 001003000
004 Element 4 3 2 001002004
005 Element 5 3 3 001003005
The only drawback is rather long cpath field for the "high" trees...
April 12, 2007 9:19 am
- shadow122
- Member


Re: Discuss article: "Tree-type structures storage in the database"
I agree with Mr.SMart – it’s better to save a tree with such a variant. I’ve made like this myself. At this the base must render an already formed tree (instead of forming a script on PHP!!!). It proved to work much faster. And field with cPath shouldn’t be transmitted to the client. It is used by the base – it is formed and handled with the base. And you are not to worry about high trees – everything works fast.
April 12, 2007 9:31 am
- mastaweb99
- Member


Re: Discuss article: "Tree-type structures storage in the database"
It proved to work much faster.
What exsactly have you checked? Can you show the tests?
April 12, 2007 9:45 am
- mambojim
- Member


Re: Discuss article: "Tree-type structures storage in the database"
It would be good to see functions for branches' transference and level raising. I cannot find this anywhere in the articles 
April 12, 2007 10:07 am
- mastaweb99
- Member


Re: Discuss article: "Tree-type structures storage in the database"
mambojim, branches' transference is done with method $tree->moveAll($id, $new_parent);
$id – nod’s identifier which should be transferred (and its children nodes should be transferred as well)
$new_parent – new parent nod for $id
April 12, 2007 10:25 am
- mmwfan
- Member


Re: Discuss article: "Tree-type structures storage in the database"
Mr.SMart, could you tell in detailes about cpath field formation. It seems to me that nothing except for Oracle can form it.
April 12, 2007 12:54 pm
- steven9x
- Member


Re: Discuss article: "Tree-type structures storage in the database"
As to the correction made by you in the moveAll function:
1. Thanks.
2. It functions better.
3. I’ve noticed a bug: when we transfer a nod one level up (closer to the root) its children become spread over its new brothers in a strange way.
April 12, 2007 1:35 pm
- R@mzess
- Member


Re: Discuss article: "Tree-type structures storage in the database"
By the way, I found a bug in the insert() method.
It’s impossible to transmit the result of MySQL-function work as a value in the $data variable.
For instance, NOW in the datetime field if such one has been created in the categories table. Although it’s more likely to be a simple restriction than a bug. The reason is $fld_values = '\''.implode('\',\'', array_values($data)).'\',';
April 12, 2007 1:59 pm
- sam43inwood
- Member


Re: Discuss article: "Tree-type structures storage in the database"
I've used your class. Everything works perfectly. I have one question only (or maybe it is a request) - to make function for element transference along the branch (not into the parent's root but within its own group), for instance, MoveUp, MoveDown. It seems to be wrong to me to write a function of my own. As I understand this question has been already discussed before.
April 12, 2007 2:10 pm
- jjjlc1983
- Member


Re: Discuss article: "Tree-type structures storage in the database"
I'm sorry for writing here but I haven't found any other place to ask my question... What about non $dbh=new CDataBase("dbname", "localhost", "root", "password"); interface to the data base? If it is PEAR - DB, nothing works... Or maybe I'm wrong? (As far as data base may be different from MySQL)
Last edited by jjjlc1983 (April 13, 2007 9:01 am)


