Categories > TinyButStrong general >

Outputting a multi-dimensional array with TBS

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: worchyld
Date: 2004-07-23
Time: 19:12

Outputting a multi-dimensional array with TBS

Outputting a multi-dimensional array with TBS.

I want to use TBS to output a multi-dimensional array with TBS.

PHP code:
    $user2_array[] = array (
        array (
            fixIt($row['u1_IDno']),
            fixIt($row['firstname']),
            fixIt($row['surname']),
            fixIt($row['email'])
        )
    );

    $TBS->MergeBlock('blk',$user2_array);

HTML:
    <p>[blk.user2_array;block=p]</p>

But this is not working. 

How do I output a multi-dimensional array with TBS?

Thanks.
By: Skrol29
Date: 2004-07-24
Time: 01:14

Re: Outputting a multi-dimensional array with TBS

Hi,

I don't understand what you're trying to do.
TBS can do mutli-dimensional array but only one value per TBS fields. And it can't guess the keys, you have to tell it in the Template.

For example with you PHP snippet:
<p>[blk.0.0;block=p]</p>
will display fixIt($row['u1_IDno'])
By: worchyld
Date: 2004-07-24
Time: 02:04

Re: Outputting a multi-dimensional array with TBS

I'm sorry, but I thought my code was pretty easy to understand by itself.

$user2_array[] = array (
array (
fixIt($row['u1_IDno']),
fixIt($row['firstname']),
fixIt($row['surname']),
fixIt($row['email'])
)
);

$TBS->MergeBlock('blk',$user2_array);

Fix it is a function that simply cleans up after looking at a particular row in a database.

The query in the above example outputs all data from a SQL command to an array.

I want TBS to output the whole contents of the array I've captured into my HTML template.

So, in my HTML template, I want it do this;

<p>output contents of array in the html</p>

I hope this is clearer.

I will try your example.  Thank you for your time!
By: worchyld
Date: 2004-07-24
Time: 10:54

Re: Outputting a multi-dimensional array with TBS

Okay, let me put the issue into context.

I have two queries in my php. The first gives the details which power the second.

I'm wanting to create a HTML email using TBS to present the recipient with a list of people.

For example:
Dear person 1,
Here are your friends:
        <!-- start outputting the results of query 2, either from
               the array, or straight from the db //-->

        * person 2
        * person 3
        * person 4

        <!-- repeat this bit until query 2 is exhausted. //-->

In order to achieve this, I have my code structured as follows:

1. Query 1, retrieve Person 1 from 'USER' table
2. Query 2, retrieve Person 2 from 'USER' table where Person 1 occurs.
3. Add current results of query 2 into the TBS template
4. Repeat Step 2 until Query 2 is finished
5. Output the template here.
6. Repeat Step 1 until Query 1 is finished.

The problem I am experiencing is finding a way of getting TBS to output the current row results of step 3 into my current template.

I want it to build up an array, or something similar, then as it's building it up, it spits it out in my TBS HTML Template.

Like this;

1. Query 1 gives person_id_1 = 1
2. Query 2 gives person_id_2 = 2  (STEP X)
     2a. Add this current row result into the TBS HTML template.
3. Repeat 2 until query 2 is exhausted, (STEP X = STEP X + 1)
4. Repeat 1 until query 1 is exhausted.

In summary, all I want to do is have an E-mail which collects all the results of query 2, dump this data into my TBS HTML template.

(See top example)

The only way I can think of doing it is via arrays, but I'd appreciate any help you can give with this.

Thanks.
By: worchyld
Date: 2004-07-24
Time: 16:08

Re: Outputting a multi-dimensional array with TBS

I've fixed it now.

I dumped all my required fields into a singular array, then I just changed my PHP code to talk differenty to TBS.

Thanks for your help!