By: help with dynamic tables
Date: 2006-10-09
Time: 13:28
|
help with dynamic tables
my test code looks like this.
php code;
$nbr_col = 8;
$nbr_row = 8;
for ($col = 1; $col <= $antalperlinie; $col++){
$columns[$col] = 'column_'.$col;
}
$data = array();
for ($row=1;$row<=$nbr_row;$row++) {
$record = array();
for ($col=1;$col<=$nbr_col;$col++) {
$record[$columns[$col]] = $row * $col;
}
$data[$row] = $record;
}
$TBS = new clsTinyButStrong;
$TBS -> LoadTemplate('templates/index2.tpl');
$TBS -> MergeBlock('aps',$apsoption);
$TBS->MergeBlock('c2',$columns);
$TBS->MergeBlock('r',$data);
$TBS -> Show();
template:
<table border="1" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#F0F0F0">
<td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center">[r.$;block=tr]</div>
[r.[c2.val;block=td]]
</div>
</td>
</tr>
</table>
i have two problems.
1) the easy one i think. Can i do [r.$;block=tr] so that is not writing anything and just do the tr?
2) the big problem. for each tr i'll need to make an extra tr with a colspan of [var.nbr_col] how can i do this? remeber it still needs to be dynamic
ps. the $data will be mysql data when its all done, this is just for testing
|
By: Skrol29
Date: 2006-10-10
Time: 19:53
|
Re: help with dynamic tables
Hi,
1) [r;block=tr] works fine for this
2) Extend you block like this:
<tr> [r.block=tr+tr] ... </tr>
<tr> ... </tr>
|
|
By: kasper
Date: 2006-10-18
Time: 01:30
|
Re: help with dynamic tables
i just get
TinyButStrong Error in field [r.block...] : item 'block' is not an existing key in the array.
|
By: Skrol29
Date: 2006-10-18
Time: 01:40
|
Re: help with dynamic tables
It was a mistake, correct code should be like this:
<tr> [r;block=tr+tr] ... </tr>
<tr> ... </tr>
|
|
By: kasper
Date: 2006-10-18
Time: 02:33
|
Re: help with dynamic tables
ok is what u mean now but [r;block=tr+tr] echos array
table border="1" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#F0F0F0">
<td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center"></div>
1 </div></td><td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center">Array</div>
2 </div></td><td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center">Array</div>
3 </div></td><td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center">Array</div>
4 </div></td><td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center">Array</div>
5 </div></td>
</tr>
|
By: kasper
Date: 2006-10-18
Time: 16:06
|
Re: help with dynamic tables
in other words after the first cell in each row [r;block=tr+tr] prints "array" why is that?
table border="1" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#F0F0F0">
<td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center">[r;block=tr+tr]</div>
[r.[c2.val;block=td]] </div></td>
</tr>
<tr bgcolor="#F0F0F0">
<td width="30" bgcolor="#FFFFFF" colspan="[var.antalperlinie]"><div align="center">test</div></td>
</tr>
</table>
<tr bgcolor="#F0F0F0">
<td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center"></div>
1 </div></td><td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center">Array</div>
2 </div></td><td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center">Array</div>
3 </div></td><td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center">Array</div>
4 </div></td><td width="30" bgcolor="#FFFFFF"><div align="center">
<div align="center">Array</div>
5 </div></td>
</tr>
<tr bgcolor="#F0F0F0">
<td width="30" bgcolor="#FFFFFF" colspan="5"><div align="center">test</div></td>
</tr>
|
By: Skrol29
Date: 2006-10-18
Time: 16:59
|
Re: help with dynamic tables
Hi Kasper,
You have this strange behavior because the tag [r;block=tr+tr] is repeated for each <td> when block "c2" is merged.
Then, the first tag [r;block=tr+tr] is used for the block definition (you can see that at the first cell, it doesn't appear), and other same tags that follow are used to try to merge data. Thta's why you have Array() instead.
The avoid this behavior, just move the tag [r;block=tr+tr] outside the area of block "c2".
For exemple:
<table border="1" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#F0F0F0">
[r;block=tr+tr]
<td width="30" bgcolor="#FFFFFF">
<div align="center">[r.[c2.val;block=td]] </div>
</td>
</tr>
<tr bgcolor="#F0F0F0">
<td width="30" bgcolor="#FFFFFF" colspan="[var.antalperlinie]">
<div align="center">test</div>
</td>
</tr>
</table>
|
|
By: kasper
Date: 2006-10-19
Time: 04:57
|
Re: help with dynamic tables
ok i think i got it all now but i have a problem with sub-blocks.
i have writen some more on the code and it now looks like this
///THE PHP:
$nbr_row = $antalperside / $antalperlinie;
for ($col = 1; $col <= $antalperlinie; $col++){
$columns[$col] = 'column_'.$col;
}
$data = array();
$row = 1;
$col = 1;
$count = 0;
while($resultat = mysql_fetch_array($find_ressultet)){
$data[$row]["column_".$col]["id"] = $resultat['id'];
$data[$row]["column_".$col]["mediumx"] = $resultat['mediumx'];
$data[$row]["column_".$col]["mediumy"] = $resultat['mediumy'];
$data[$row]["column_".$col]["mediumyp"] = $resultat['mediumy'] +20;
$data[$row]["column_".$col]["taeller"] = $resultat['taeller'];
$data[$row]["column_".$col]["dato"] = $resultat['dato'];
$data[$row]["column_".$col]["datosp"] = datesplitter($resultat['dato']);
$data[$row]["column_".$col]["x"] = $resultat['x'];
$data[$row]["column_".$col]["y"] = $resultat['y'];
$data[$row]["column_".$col]["str"] = $resultat['str'];
$data[$row]["column_".$col]["filnavn"] = $resultat['filnavn'];
$data[$row]["column_".$col]["upload_af"] = $resultat['upload_af'];
$data[$row]["column_".$col]["count"] = $count;
$base = "cms_billedDB";
include'../mysql.inc';
$find_kategoriger = mysql_query(" SELECT DISTINCT kategorier.tekst, kategorier.id FROM kategorier, link WHERE link.billed_id = '$resultat[id]' AND kategorier.id = link.kategori_id ");
mysql_close($connection);
while($kategori = mysql_fetch_array($find_kategoriger)){
$data[$row]["column_".$col]['kdata'][] = array('id' => $kategori[id], 'tekst' => $kategori[tekst]);
}
$count++;
if($col == $antalperlinie){
$row++;
$col = 1;
}else{
$col++;
}
}
$linksoter = urllink('soter');
$linksoterr = urllink('soterr');
$linkaps = urllink('aps');
$TBS = new clsTinyButStrong;
$TBS -> LoadTemplate('templates/index2.tpl');
$TBS -> MergeBlock('aps','array',$apsoption);
$TBS -> MergeBlock('col','array',$columns);
$TBS -> MergeBlock('kdata','array','$data[%p1%][%p2%][kdata]');
$TBS -> MergeBlock('cell','array',"data");
$TBS -> Show();
|
/// A PREVIEW OF THE $DATA ARRAY
Array
(
[1] => Array
(
[column_1] => Array
(
[id] => 880
[mediumx] => 450
[mediumy] => 600
[mediumyp] => 620
[taeller] => 4
[dato] => 0000-00-00
[datosp] => 00/??/0000
[x] => 2112
[y] => 2816
[str] => 1537
[filnavn] => STA60044.JPG
[upload_af] => kv
[count] => 0
[kdata] => Array
(
[0] => Array
(
[id] => 1
[tekst] => tmp
)
)
)
...
|
AND LITTLE OF THE TEMPLATE
<table border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
[cell;block=tr+tr]
<td align="center" valign="top" width="150" height="100">
<div width="150" height="150" onMouseOver="info('vis',[cell.$])" onMouseOut="info('',[cell.$])" style="width:150px; height:118px;">
<img src="bdbgen.php?id=[cell.[col.val;block=td].id]&str=1" border="0" valign="middle" style="cursor: hand;" onClick="popup('bdbpopup.php?id=[cell.[col.val].id]&h=[cell.[col.val].mediumyp]&w=[cell.[col.val].mediumx]&str=2','popup',[cell.[col.val].mediumx],[cell.[col.val].mediumyp]);">
</div>
<div id="infoboxkat[cell.[col.val].count]" style="display:none;">
<a href="index.php?katid=[kdata.id; block=a; p1= [cell.$]; p2= [col.val]]"></a>
</div>
</span>
<span onMouseOver="info('hojr', [cell.$]);" onMouseOut="info('',[cell.$]);">
<img src="gfx/hojr.gif" style="cursor: hand;" onclick="document.location = 'bdrot.php?[var.server.QUERY_STRING; if [val] == ''; then id=[cell.[col.val].id]; else [var.server.QUERY_STRING]&id=[cell.[col.val].id]]&vej=hoj'">
</span>
</td>
</tr>
<tr>
<td id="raekke[cell.$]" colspan="[var.antalperlinie]" align="center" style="color:#F8A426; background-repeat:repeat-x;"> </td>
</tr>
</table>
|
the problem is that i'll get
TinyButStrong Error when merging block [kdata] : invalid query '$data[[cell.$]][column_1][kdata]' because global variable '$data' is not found.
why does it write [cell.$] and not that value. it works other places in the code.
by the way thanx for all ur help until now. tinybutstrong is alittle hard to get into when u haven't tryed before but after that i goes fast.
|
By: kasper
Date: 2006-10-19
Time: 05:05
|
Re: help with dynamic tables
ofcause ill need to do this
$TBS -> MergeBlock('cell','array',"data");
$TBS -> MergeBlock('kdata','array','$data[%p1%][%p2%][kdata]');
|
insted of this
$TBS -> MergeBlock('kdata','array','$data[%p1%][%p2%][kdata]');
$TBS -> MergeBlock('cell','array',"data");
|
but i still get TinyButStrong Error when merging block [kdata] : invalid query '$data[1][column_1][kdata]' because global variable '$data' is not found.
|
By: kasper
Date: 2006-10-19
Time: 05:59
|
Re: help with dynamic tables
ok i found out what was wrong.
1) it needs to be $TBS -> MergeBlock('kdata2','array','data[%p1%][%p2%][kdata]'); no $ infront of data
2) its not smart to call it kdata when the string is 'data[%p1%][%p2%][kdata]'
|
|
Posting in progress.
Please wait...
|