Categories > TinyButStrong general >

tree structure prob

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: donatello
Date: 2007-11-04
Time: 22:03

tree structure prob

Hi,
i've read your tree structure example in the tips&tricks section, it's very interesting. Trying to reproduce it but doesn't work. No error, bit no results.
I just want to display the name of menu items (no id) + name of submenus (if exists) for each of the menu items.
Thanks if u have some advice for me!

My table:
CREATE TABLE `rubriques` (
  `idRub` int(10) NOT NULL auto_increment,  //id
  `parentId` tinyint(2) NOT NULL default '0',    //parent of menu item
  `nomRub` varchar(200) NOT NULL default '',  //name of menu item
  `contenu` text NOT NULL,  //content
  PRIMARY KEY  (`idRub`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;

Myphp:
$query = "SELECT * FROM rubriques WHERE parentId=0 ORDER BY idRub ASC";
$query2 = "SELECT * FROM rubriques WHERE parentId=%p1% ORDER BY idRub ASC";

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('html/list_rubriques.htm');

// Fusion
$TBS->PlugIn(TBS_BYPAGE,$PageSize,$PageNum,$RecCnt); // Le prochain bloc sera fusionné en mode Par-Page
$RecCnt = $TBS->MergeBlock('blk', 'mysql', $query);
          $TBS->MergeBlock('sub', 'mysql', $query2);

// Fusion navbar
$TBS->PlugIn(TBS_NAVBAR,'nv1','',$PageNum,$RecCnt,$PageSize);

$TBS->Show();

function f_ondata_tree($BlockName,&$CurrRec,$RecNum) {
global $SrcSub;
// Add the source of the Subitem tables as a new field of the current row.
$CurrRec['subitems'] = str_replace('[blk.nomRub]',$CurrRec['nomRub'],$SrcSub);
}

My html:
<table border="0" class="admin_central">
  <tr bgcolor="#f1f1f1">
    <td> [blk.nomRub;block=tr]&nbsp;&nbsp;</td>
    <td><div align="right">&nbsp;</td>

  </tr>
          <tr>
          <td>[sub.nomRub;block=tr;p1=[blk.nomRub];ondata=f_ondata_tree]</td>
        </tr>

</table>
By: Skrol29
Date: 2007-11-05
Time: 16:47

Re: tree structure prob

Hi Donatello,

Several thinks are missing to perform a hierarchical tree.

First, the main block "blk" should be embedding the subblock "sub", but it is not the case in your template.
[blk.nomRub;block=tr+tr] should work better.

There is also a special step in the tip&trick which consists in retrieving a part of the template. It is done with the "sparent" block in the HTML, and with a GetBlockSource() in the PHP. You have to do this step.
By: donatello
Date: 2007-11-05
Time: 16:54

Re: tree structure prob

hello skrol,
i've noticed the "sparent" stuff, but your example was still working without it. And my first reflex is always do delete what can be, so that the script is simplified to the max and i can understand it.
Maybe i've been tricked by the cache?

I'll have a deeper look in your example.
thanks 4 this quick answer!

By: Skrol29
Date: 2007-11-05
Time: 17:12

Re: tree structure prob

Hi,

You can also try the opposite way: make the example run as is at your local site, and then turn it step by step to what you want.