By: Skrol29
Date: 2007-06-24
Time: 01:04
|
display data with a tree or hierarchical structureHello,
They are many questions on how to display data with a tree or hierarchical structure using TBS 3.2.0. First of all I have to recall that hierarchical data can be something quite complicated and only few database systems give you features to manage and display data such a way. That's why they are several ways of managing it with common database system. The more common way we met around is to save all items in table and have a Parent field which refers to the id of the parent item in the same table. The example given under in this post is for that way of saving data. This way is smart but it makes difficult or expensive to retrieve the whole tree structure. If you could also save the level of the item, it will be very faster to retrieve the tree and it won't be so complicated to do it with TBS. In the same spirit, if you could retrieve the tree yourself into a PHP array, then it would be faster and easier to display it with TBS. Just be inspired by this example to adapt it to your precise case. In this example, we have a simple table [t_test_tree] with fields (m_id, m_parent, m_title). The SQL source to build and feed the table is given at the end of this post. Some technical explanations: They are two blocks, one for the root items and another one for all subitems. We will use the subblocks feature of TBS to merge child items for each and every subitems. That can be expensive because this means there will be as many SQL queries as they are items in the tree. In order to make the loop, we save the subitem block before the merge, and we re-insert it for each items using an "ondata" function. HTML:
PHP:
SQL:
|
|||
By: Martin
Date: 2007-06-24
Time: 05:33
|
Re: display data with a tree or hierarchical structureThanks a lot Skrol !!!! I test it, and run perfect. ;)
|
|||
By: Coyote
Date: 2007-06-26
Time: 10:09
|
Re: display data with a tree or hierarchical structureThanks a lot...
works great with <table>... can you add an example with <ul><li></li></ul> |
|||
By: andy
Date: 2007-10-06
Time: 06:48
|
Re: display data with a tree or hierarchical structureCould you give an example on <ul><li></li><ul>? Thanks
|
|||
By: Skrol29
Date: 2007-10-19
Time: 23:20
|
Re: display data with a tree or hierarchical structureHi,
Here is the HTML template for <ul><li> hierachical display:
|
|||
By: Rromulo
Date: 2008-01-23
Time: 14:20
|
Re: display data with a tree or hierarchical structureIS PERFECT !!!!!
I am using a base sql with 474 columns, he was half slow to generate my menu - tree , exists some better form? |
|||
By: MBt
Date: 2008-05-17
Time: 01:50
|
Re: display data with a tree or hierarchical structureHello all.
I found my way to do the same using an array instead of multiple queries (I guess it's faster with an array) but when I use this script throughout 'subtpl' the function passed to "ondata" is never called so only fist tree level is displayed. I tried : 1/ to declare the function in main script 2/ to declare the function in sub script 3/ to use ObjectRef and ~functionName 4/ to use a dummy name for the function (I don't even get an error) Do you guys have the 5th possible try? Thanks, MBt |
|||
By: Skrol29
Date: 2008-05-17
Time: 01:52
|
Re: display data with a tree or hierarchical structureHi,
What is the error message you've got ? |
|||
By: MBt
Date: 2008-05-17
Time: 11:17
|
Re: display data with a tree or hierarchical structureHi,
I do not get any error message. did anyone tried to run the templte you gave in this thread as a subtpl? I'll try to give you my files but I need to clean them up a bit to make it more readable... MBt |
|||
By: MBt
Date: 2008-05-17
Time: 13:04
|
Re: display data with a tree or hierarchical structureHi Skrol29,
I started a new thread on this issue to treat this out of this Tips&Tricks post. Please reply here : http://www.tinybutstrong.com/forum.php?msg_id=8926 MBt |