Categories > OpenTBS with DOCX >

multidimensional array

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: new2TBS
Date: 2013-07-31
Time: 08:23

multidimensional array

Dear friends
I want to export below array to excel.
I tried suggestion posted here in forum but with no success.

Array
(
    [2008] => Array
        (
            [B1] => Array
                (
                    [D1] => Array
                        (
                            [jan] => 100
                            [feb] => 200
                            [mar] => 300
                            [apr] => 400
                            [may] => 100
                            [jun] => 150
                        )

                    [D2] => Array
                        (
                            [jan] => 150
                            [feb] => 210
                            [mar] => 210
                            [apr] => 158
                            [may] => 142
                            [jun] => 120
                        )

                )

        )

    [2009] => Array
        (
            [B1] => Array
                (
                    [D1] => Array
                        (
                            [jan] => 100
                            [feb] => 200
                            [mar] => 300
                            [apr] => 400
                            [may] => 100
                            [jun] => 150
                        )

                    [D2] => Array
                        (
                            [jan] => 150
                            [feb] => 210
                            [mar] => 210
                            [apr] => 158
                            [may] => 142
                            [jun] => 120
                        )

                )

            [B2] => Array
                (
                    [D1] => Array
                        (
                            [jan] => 100
                            [feb] => 200
                            [mar] => 300
                            [apr] => 400
                            [may] => 100
                            [jun] => 150
                        )

                    [D2] => Array
                        (
                            [jan] => 150
                            [feb] => 210
                            [mar] => 210
                            [apr] => 158
                            [may] => 142
                            [jun] => 120
                        )

                )

        )

    [2013] => Array
        (
            [B1] => Array
                (
                    [D1] => Array
                        (
                            [jan] => 100
                            [feb] => 200
                            [mar] => 300
                            [apr] => 400
                            [may] => 100
                            [jun] => 150
                        )

                    [D2] => Array
                        (
                            [jan] => 150
                            [feb] => 210
                            [mar] => 210
                            [apr] => 158
                            [may] => 142
                            [jun] => 120
                        )

                )

        )

)

I cannot attach the image, so giving html
<table width="100%" border=1>
    <tr>
        <td>Year</td>
        <td>branch</td>
        <td>division</td>
        <td>jan</td>
        <td>feb</td>
        <td>mar</td>
        <td>apr</td>
        <td>may</td>
        <td>jun</td>
    </tr>

    <tr>
        <td rowspan="2">2008</td>
        <td rowspan="2">B1</td>
        <td>D1</td>
        <td>100</td>
        <td>200</td>
        <td>300</td>
        <td>400</td>
        <td>100</td>
        <td>150</td>
    </tr>

    <tr>
        <td>D2</td>
        <td>150</td>
        <td>210</td>
        <td>210</td>
        <td>158</td>
        <td>142</td>
        <td>120</td>
    </tr>

    <tr>
        <td rowspan="4">2009</td>
        <td rowspan="2">B1</td>
        <td>D1</td>
        <td>100</td>
        <td>200</td>
        <td>300</td>
        <td>400</td>
        <td>100</td>
        <td>150</td>
    </tr>

    <tr>
        <td>D2</td>
        <td>150</td>
        <td>210</td>
        <td>210</td>
        <td>158</td>
        <td>142</td>
        <td>120</td>
    </tr>
    <tr>
        <td rowspan="2">B2</td>
        <td>D1</td>
        <td>100</td>
        <td>200</td>
        <td>300</td>
        <td>400</td>
        <td>100</td>
        <td>150</td>
    </tr>

    <tr>
        <td>D2</td>
        <td>150</td>
        <td>210</td>
        <td>210</td>
        <td>158</td>
        <td>142</td>
        <td>120</td>
    </tr>

</table>

would you please guide me on how to achieve this. also need total per year and branch.

In excel, i used below

[a.finyr;block=row;sub1]    [b.scid;block=row;p1=[fd.$];p2=[a.finyr] ]

Thanks in advance
By: Skrol29
Date: 2013-07-31
Time: 11:32

Re: multidimensional array

Hi,

Since you data are orgenized with arrays and sub arrays, then you have to use sub-blocks.
They are online examples:
http://www.tinybutstrong.com/examples.php?e=subblock&m=result

Otherwise you have to use a simple array of flat "records".
By: new2TBS
Date: 2013-07-31
Time: 12:02

Re: multidimensional array

Hi Skrol

Thanks for your reply.
I am trying to export this info in excel sheet.
I read about blocks and subblocks, but could not implement it, somehow on excel sheet.

The issue, is its multi dimensional array and i cannot keep columns fixed.
FE: I dont know, which year will be included. I read in documentation, it can be read with $ sign and it worked correctly. But when i come to level of branch, i dont get values.

Would you please elaborate a bit, on how should i proceed and what will be substitution in excel sheet. I am totally lost at the moment. :-(

Thanks again.
By: Skrol29
Date: 2013-08-20
Time: 23:54

Re: multidimensional array

Hi new2TBS,

> The issue, is its multi dimensional array and i cannot keep columns fixed.

The keys are not fixed but you know the structure: $data[$year][$branch][$division][$month]
So scan it to build a new recordset: $data2[] = array('year'=>..., 'branch'=>...,'division'=>...,'jan'=>...)

With this new flat recorset, the table will be easy displayed. You just have to merged cells but this is not possible with OpenTBS for now, only in Ms Word.