Categories > TinyButStrong general >

sub-blocks with arrays

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: SunWuKung
Date: 2006-06-30
Time: 13:06

sub-blocks with arrays

Let me first congratulate you for TBS.
Then I would like to ask your help:)

I have the following template:

[ratings.response;block=table:table-row]
[sentences;block=begin;p1=[ratings.response]]
  [sentences.ic]
  [sentences.rs]
[sentences;block=end]

I have the following PHP code
$ratings and $sentences are arrays I get from a db
$OOo->MergeBlock('ratings',$ratings);
$OOo->MergeBlock('sentences',$sentences, 'sentences[%p1%]');

What happens is that I get all sentences under each rating - so the condition is not observed. Can you help me with this?
To be honest I don't understand the logic of it either p1 becomes the value of ratings.response - and it is compared to what?

Thanks for the help.
SWK
By: Skrol29
Date: 2006-06-30
Time: 13:20

Re: sub-blocks with arrays

Hi Sun WuKung,

You have all sentences under each rating because your PHP is wrong.
Just replace
$OOo->MergeBlock('sentences',$sentences, 'sentences[%p1%]');
with :
$OOo->MergeBlock('sentences','array', 'sentences[%p1%]');

In the code you've submited, the query 'sentences[%p1%]' is just ignored because $sentences is data itself.
By: Skrol29
Date: 2006-06-30
Time: 13:23

Re: sub-blocks with arrays

> To be honest I don't understand the logic of it either
> p1 becomes the value of ratings.response - and it is compared to what?

rating.response => p1
'sentences[%p1%]' => $sentences[rating.response]
By: SunWuKung
Date: 2006-06-30
Time: 14:03

Re: sub-blocks with arrays

Thanks for your quick reply.
I understand now the logic and have changed now the line to:
$OOo->MergeBlock('sentences','array', 'sentences[%p1%]');

however I now get the following error:
TinyButStrong Error in field [sentences.rs...] : item 'rs' is not an existing key in the array.
TinyButStrong Error in field [sentences.ic...] : item 'ic' is not an existing key in the array.

which is strange, because so far it displayed them (with all records) which suggests that they are there...

could you tell me what might be happening here?
thx
SWK
By: Skrol29
Date: 2006-06-30
Time: 15:47

Re: sub-blocks with arrays

Hi,

When your old command
  $OOo->MergeBlock('sentences',$sentences, 'xxxxxxxxx');
used to merge correctly the fields [sentences.ic] and [sentences.rs],
then it means that $sentences is an array structured like this:
  $sentences[keys1] = array('ic'=>val_ic_1, 'rs'=>...);
  $sentences[keys2] = array('ic'=>val_ic_2, 'rs'=>...);
  ...

But when you call
  $OOo->MergeBlock('sentences','array', 'sentences[%p1%]');
the is assumes that $sentences is tructured like this:
  $sentences[rating][keys1] = array('ic'=>val_ic_1, 'rs'=>...);
  $sentences[rating][keys2] = array('ic'=>val_ic_2, 'rs'=>...);
  ...

That why (ic) and (rs) are not found where expected.

By: SunWuKung
Date: 2006-07-03
Time: 20:41

Re: sub-blocks with arrays

this was finally too complicated for me, so I just did it with one query and a headergroup

thanks for the help
SWK