Categories > TinyButStrong general >

tag tbs for tree, help me

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: thuc101
Date: 2010-03-21
Time: 05:00

tag tbs for tree, help me

test.php
------
include_once("tbs_class.php");
$x='hello';
$tree[]=array('id'=>0,'root'=>-1,'item'=>'item0');
$tree[]=array('id'=>1,'root'=>0,'item'=>'item1');
$tree[]=array('id'=>2,'root'=>1,'item'=>'item2');
$tree[]=array('id'=>3,'root'=>1,'item'=>'item3');
$tree[]=array('id'=>4,'root'=>0,'item'=>'item4');
$tree[]=array('id'=>5,'root'=>0,'item'=>'item5');
$TBS =new clsTinyButStrong;
$TBS->LoadTemplate("test.htm");
$TBS->MergeBlock('blk',$tree);
$TBS->Show();
----
test.htm
-------
[onshow.x]
<table border="1">
<tr>
<td>[blk.id;block=tr]</td>
<td>[blk.root]</td>
<td>[blk.item]</td>
</tr>
</table>
----
how can I view?
-------------
<table width="200" border="1">
  <tr>
    <td colspan="3">item0</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2">item1</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>item2</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>item3</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2">item4</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2">item5</td>
  </tr>
</table>

-------------
help me, thank
By: thuc101
Date: 2010-03-22
Time: 09:39

Re: this is my solution, but I need some help

test.php
<?php
include_once('tbs_class.php') ;
$tree[]=array('id'=>0,'root'=>-1,'item'=>'item0');
$tree[]=array('id'=>1,'root'=>0,'item'=>'item1');
$tree[]=array('id'=>2,'root'=>0,'item'=>'item2');
$tree[]=array('id'=>3,'root'=>2,'item'=>'item3');
$tree[]=array('id'=>4,'root'=>2,'item'=>'item4');
$tree[]=array('id'=>5,'root'=>2,'item'=>'item5');
$tree[]=array('id'=>6,'root'=>2,'item'=>'item6');
$tree[]=array('id'=>7,'root'=>2,'item'=>'item7');
$tree[]=array('id'=>8,'root'=>2,'item'=>'item8');
$tree[]=array('id'=>9,'root'=>2,'item'=>'item9');
$t_level=$tree;
$i=0;
while($i<count($tree)){
    $j=$tree[$i]['root'];
    $c=0;
    while($j!=-1){
        $c++;
        $j=$tree[$j]['root'];
    }
    $t_level[$i]['level']=$c;
    $i++;
}
printf('<hr>');
for($i=0;$i<count($t_level);$i++){
    $da_duyet[$i]=0;
}
$stack=array();
$start=0;
$k=-1;
array_push($stack,$start);
while(count($stack)!=0){
    $i=array_shift($stack);
    $k++;
    $t_order[$k]['order']=$k;
    $t_order[$k]['id']=$t_level[$i]['id'];
    $t_order[$k]['root']=$t_level[$i]['root'];
    $t_order[$k]['item']=$t_level[$i]['item'];
    $t_order[$k]['level']=$t_level[$i]['level'];
    $da_duyet[$i]=1;
    for($j=0;$j<count($t_level);$j++){
        if($da_duyet[$j]==0 && $t_level[$j]['root']==$i){
            array_push($stack,$j);
        }
    }
}
$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('test.htm') ;
$TBS->MergeBlock('blk',$t_order) ;
$TBS->Show() ;
//Event functions
function on_event($BlockName,&$CurrRec,$RecNum){
  $CurrRec['item']=level($CurrRec['level']).$CurrRec['item'];
}
function level($i){
    $st='';
    for($j=0;$j<$i;$j++){
        $st=$st.'&nbsp;&nbsp;&nbsp;';
    }
    return $st;
}
?>
-----------------
<html>
<head>
<title>TinyButStrong</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="tbs_us_examples_0styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<table border="1">
<tr bgcolor="#666666">
  <td>id</td>
  <td>root</td>
  <td>item</td>
  <td>level</td>
</tr>
<tr>
<td>[blk.id;block=tr;ondata=on_event]</td>
<td>[blk.root]</td>
<td bgcolor="#CCCCCC">[blk.item;htmlconv=no]</td>
<td>[blk.level]</td>
</tr>
</table>
</body>
</html>

!!!help me, how can I hide colum id,level...
By: Skrol29
Date: 2010-03-22
Time: 09:56

Re: this is my solution, but I need some help

Hi Thcu101,

I don't understand what is your problem.
Can you give more details about what to need to have?
By: thuc101
Date: 2010-03-22
Time: 10:41

Re: this is my solution, but I need some help

this is my result
<table border="1">
<tr bgcolor="#666666">
  <td>id</td>
  <td>root</td>
  <td>item</td>

  <td>level</td>
</tr>
<tr>
<td>0</td>
<td>-1</td>
<td bgcolor="#CCCCCC">item0</td>
<td>0</td>
</tr><tr>
<td>1</td>
<td>0</td>

<td bgcolor="#CCCCCC">&nbsp;&nbsp;&nbsp;item1</td>
<td>1</td>
</tr><tr>
<td>2</td>
<td>0</td>
<td bgcolor="#CCCCCC">&nbsp;&nbsp;&nbsp;item2</td>
<td>1</td>
</tr><tr>
<td>3</td>
<td>2</td>

<td bgcolor="#CCCCCC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item3</td>
<td>2</td>
</tr><tr>
<td>4</td>
<td>2</td>
<td bgcolor="#CCCCCC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item4</td>
<td>2</td>
</tr><tr>
<td>5</td>
<td>2</td>

<td bgcolor="#CCCCCC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item5</td>
<td>2</td>
</tr><tr>
<td>6</td>
<td>2</td>
<td bgcolor="#CCCCCC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item6</td>
<td>2</td>
</tr><tr>
<td>7</td>
<td>2</td>

<td bgcolor="#CCCCCC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item7</td>
<td>2</td>
</tr><tr>
<td>8</td>
<td>2</td>
<td bgcolor="#CCCCCC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item8</td>
<td>2</td>
</tr><tr>
<td>9</td>
<td>2</td>

<td bgcolor="#CCCCCC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item9</td>
<td>2</td>
</tr>
</table>

It is work good, but now I want to hide some collume id,level. How can I do that?
By: thuc101
Date: 2010-03-22
Time: 12:41

Re: this is my solution, but I need some help

hi, Mr Skrol29
My new test.htm
<html>
<head>
<title>TinyButStrong</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="tbs_us_examples_0styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<table border="1">
<tr bgcolor="#666666">
  <td>level</td>
  <td>item</td>
  </tr>
<tr>
  <td bgcolor="#CCCCCC">[blk.level]</td>
<td bgcolor="#CCCCCC">[blk.item;htmlconv=no;block=tr;ondata=on_event]</td>
</tr>
</table>
</body>
</html>

I want to hide collume level, but it is need for function on_event. What can I do????
By: thuc101
Date: 2010-03-22
Time: 12:50

Re: this is my solution, but I need some help

And I continue change
[node]
<table border="1">
<tr bgcolor="#666666">
  <td>&nbsp;</td>
  <td>item</td>
  </tr>
<tr>
  <td bgcolor="#CCCCCC"><div style="display:none">[blk.level]</div></td>
<td bgcolor="#CCCCCC">[blk.item;htmlconv=no;block=tr;ondata=on_event]</td>
</tr>
</table>

[/node]
It is good, but I think very poor. Do you have any diff way?
By: Skrol29
Date: 2010-03-22
Time: 14:03

Re: this is my solution, but I need some help

Hi,

You can simple delete the column from the template part.
You can have a column in the PHP side and never use it in the HTML side.
By: thuc101
Date: 2010-03-22
Time: 15:39

Re: this is my solution, but I need some help

How to do that? May you give me a example. thank you
By: Skrol29
Date: 2010-03-22
Time: 22:50

Re: this is my solution, but I need some help

like this:
<table border="1">
<tr bgcolor="#666666">
  <td>item</td>
  </tr>
<tr>
  <td bgcolor="#CCCCCC">[blk.item;htmlconv=no;block=tr;ondata=on_event]</td>
</tr>
</table>
By: thuc101
Date: 2010-03-23
Time: 07:30

Re: this is my solution, but I need some help

oh, exactly, th you!!!!!
By: thuc101
Date: 2010-03-23
Time: 07:39

Re: this is my solution, but I need some help

this is all my file
<html>
<head>
<title>TinyButStrong</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="tbs_us_examples_0styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<table border="1">
<tr>
<td bgcolor="#CCCCCC">[blk.item;htmlconv=no;block=tr;ondata=on_event]</td>
</tr>
</table>
</body>
</html>
tes.php
<?php
include_once('tbs_class.php') ;
$tree[]=array('id'=>0,'root'=>-1,'item'=>'item0');
$tree[]=array('id'=>1,'root'=>0,'item'=>'item1');
$tree[]=array('id'=>2,'root'=>0,'item'=>'item2');
$tree[]=array('id'=>3,'root'=>2,'item'=>'item3');
$tree[]=array('id'=>4,'root'=>2,'item'=>'item4');
$tree[]=array('id'=>5,'root'=>2,'item'=>'item5');
$tree[]=array('id'=>6,'root'=>2,'item'=>'item6');
$tree[]=array('id'=>7,'root'=>2,'item'=>'item7');
$tree[]=array('id'=>8,'root'=>2,'item'=>'item8');
$tree[]=array('id'=>9,'root'=>2,'item'=>'item9');
$tree[]=array('id'=>10,'root'=>9,'item'=>'item10');
$t_level=$tree;
$i=0;
while($i<count($tree)){
    $j=$tree[$i]['root'];
    $c=0;
    while($j!=-1){
        $c++;
        $j=$tree[$j]['root'];
    }
    $t_level[$i]['level']=$c;
    $i++;
}
for($i=0;$i<count($t_level);$i++){
    $da_duyet[$i]=0;
}
$stack=array();
$start=0;
$k=-1;
array_push($stack,$start);
while(count($stack)!=0){
    $i=array_shift($stack);
    $k++;
    $t_order[$k]['order']=$k;
    $t_order[$k]['id']=$t_level[$i]['id'];
    $t_order[$k]['root']=$t_level[$i]['root'];
    $t_order[$k]['item']=$t_level[$i]['item'];
    $t_order[$k]['level']=$t_level[$i]['level'];
    $da_duyet[$i]=1;
    for($j=0;$j<count($t_level);$j++){
        if($da_duyet[$j]==0 && $t_level[$j]['root']==$i){
            array_push($stack,$j);
        }
    }
}
$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('test.htm') ;
$TBS->MergeBlock('blk',$t_order) ;
$TBS->Show() ;
//Event functions
function on_event($BlockName,&$CurrRec,$RecNum){
  $CurrRec['item']=level($CurrRec['level']).$CurrRec['item'];
}
function level($i){
    $st='';
    for($j=0;$j<$i;$j++){
        $st=$st.'&nbsp;&nbsp;&nbsp;';
    }
    return $st;
}
?>
It work good, but there are some disadvanted in my solution. I want to learn more from everybody... thk to tbs!
By: TomH
Date: 2010-03-23
Time: 13:59

Re: this is my solution, but I need some help

thuc,

If you want to explore other methods... there is an example for you that has the source code: http://tomhenry.us/tbs3 go to the "Menu Tree" application shown at the top of the page.

Hope that helps,