Categories > TinyButStrong general >

Table with dynamic number of rows

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Marcus
Date: 2005-02-09
Time: 14:27

Table with dynamic number of rows

Hi Skrol,

I saw your example called 'Merge table with dynamic number of columns' in the t&t section.
My question:
Can I used the same approach for a table with dynamic number
of rows where the data is coming from a three dimensional array?
I have an 3D-array which I need to display in a table, however
for the 2nd dimension I have varibale number of entries. Since I don't know how many, the template must be able to display a table with
variable number of rows.

Thanks in advance,
Marcus
By: Skrol29
Date: 2005-02-09
Time: 16:16

Re: Table with dynamic number of rows

Hello Marcus,

I've moved you post here.

It maybe work if you use sub-blocks. First merge the main block with your array without sub-row.
Then merge sub rows on a sub-block (use dynamical query for Php array). If you need to display them horizontaly on a table, you will probably need 2 merges : one for columns names (keys) and another for column values. This is the same technic as for dynamic queries.

But I think you won't be able to merge both main-rows and sub-rows in the same <table> because an Html is supposed to have the same number of columns for each row.
By: Marcus
Date: 2005-02-10
Time: 14:35

Re: Table with dynamic number of rows

Hi Skrol,

First of all to thanks for your outstanding and fast support.
For a free program this is really excellent.

I tried several stuff this afternoon to make it work, but to no avail.
However I could simplify my array a bit. It's now 2D and consists
of a dynamic number of rows and columns. One example how it
could look like is:
Array
(
    [FQA] => Array
        (
            [0] => Managers
            [1] => Mike Duuley
            [2] => Stan Cooper
            [3] => James Gunder
        )

    [APP] => Array
        (
            [0] => Applications
            [1] => Alex Craick
            [2] => Jack Wocky
        )

    [PEN] => Array
        (
            [0] => Marketing
            [1] => Joe Mooly
        )

)
As written above the number of rows and columns is not fix.
As you can see, in this example it has 3 rows and each row has a varying number of columns. Now I need to display the values the following way (only first row for example):

<tr>
<td>Managers</td><td>Mike Duuley</td><td>Stan Cooper</td><td>James Gunder</td>
</tr>
.
.
.

Is there some code/example available on how I could do that?
I could also change the keys that represent the rows (FQA, PEN...) to numbers, like 0,1,2...

Any help appreciated!
Thanks again,
Marcus


</tr>
By: Skrol29
Date: 2005-02-10
Time: 18:56

Re: Table with dynamic number of rows

Hello Marcus,

Could you provide an example of how the complete table should be structured. If the table is made of simple rows like your example, then you'll have a various number of columns in the same table, which is not "html" clean.
By: Marcus
Date: 2005-02-10
Time: 22:37

Re: Table with dynamic number of rows

Hi Skrol,

Sorry for not being precise enough!

For each row I would need to make a new table, ie one table for
one row. So the whole array would be displayed like this:

<table>
<tr>
<td>Managers</td><td>Mike Duuley</td><td>Stan Cooper</td><td>James Gunder</td>
</tr>
</table>

<table>
<tr>
<td>Applications</td><td>Alex Craick</td><td>Jack Wocky</td>
</tr>
</table>
.
.
.

However, since the array is dynamic I need as many tables repeated as rows and in each table a dynamic number of columns (as you can see from my array structure.

Hope this helps you,
many thanks again,
Marcus

By: Skrol29
Date: 2005-02-11
Time: 10:08

Re: Table with dynamic number of rows

Hello Marcus,

Here is a solution that works.
It uses a sub-block with a dynamic query for array.

Html:
<table width="400" border="1" cellpadding="2" cellspacing="0" bordercolor="#0000FF">
  <tr>
    <td width="60">[bm.$;block=table]</td>
    <td>[bs.val;block=td;p1='[bm.$]']</td>
  </tr>
</table>

Php:
$data['FQA'] = array('Managers','Mike Duuley','Stan Cooper','James Gunder');
$data['APP'] = array('Applications','Alex Craick','Jack Wocky');
$data['PEN'] = array('Marketing','Joe Mooly');

$TBS->MergeBlock('bm',$data); // Main block
$TBS->MergeBlock('bs','array','data[%p1%]'); // Sub-block