Categories > TinyButStrong general >

Problems with MultiDimensional Arrays

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Aaron
Date: 2005-04-25
Time: 19:51

Problems with MultiDimensional Arrays

Hello everyone!

I am working on an OnlineShop with a "cart". I stored the data(products etc.) in a MultiDimensional Array which looks like this:


The "$cart"-Array:
Array
(
    [0] => Array
        (
            [id] => 1
            [pid] => 1
            [langid] => de
            [kid] => 1
            [name] => WEB 50
            [description] => some description
            [price] => 0.99
            [max] => 5
        )

    [1] => Array
        (
            [id] => 1
            [pid] => 1
            [langid] => de
            [kid] => 1
            [name] => WEB 50
            [description] => Little description of the product
            [price] => 0.99
            [max] => 5
        )
)

And the "$addons"-Array for the products (Same array-id (key 0 is for product key 0):
Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [aid] => 1
                    [langid] => de
                    [name] => Extra space....
                    [value] => 50
                    [unit] => MB
                    [price] => 0.99
                    [description] => 50 MB Extra....
                    [max] => 10
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [id] => 2
                    [aid] => 2
                    [langid] => de
                    [name] => addonx4
                    [value] => 1
                    [unit] => in Rot
                    [price] => 9.99
                    [description] => text...
                    [max] => 10
                )
            [1] => Array
                (
                    [id] => 3
                    [aid] => 1
                    [langid] => de
                    [name] => addonx1
                    [value] => 10
                    [unit] => MB
                    [price] => 5.99
                    [description] => some text
                    [max] => 1
                )
)

So, now i want to display the cart with TBS like this:
---product 1 ---
   -> addon nr. 1 for product 1
   -> addon nr. 2 for product 1
---product 2 ---
   -> addon nr. 1 for product 2
   -> addon nr. 2 for product 2

I found some useful functions in the manual (MergeBlocks()), but i  am unable zu use it :)
Can somebody help me or can give some advice for this "problem"?

Cheers,
Aaron
By: Skrol29
Date: 2005-04-25
Time: 20:11

Re: Problems with MultiDimensional Arrays

hi Aaron,

This can be done with sub-blocks, using the TBS dynamic query syntax or array.
This needs that $cart and $addons have corresponding keys.
Example:

PHP:
$TBS->MergeBlock('mb','array',$cart);
$TBS->MergeBlock('sb','array','addons[%p1%]');

HTML:
<tr>
  [mb.name;block=tr]
  <div>[sb.name;block=div;p1=[mb.$]]</div>
</tr>