Categories > TinyButStrong general >

Help needed with array merging

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Al
Date: 2003-06-30
Time: 12:48

Help needed with array merging

Hello,

I would like to submit a little tricky problem I can't get rid of from several days.
Thank you for your help if you can understand what's happening.

Here it is :

I have a file called 'index.php' containing the following lines :
<pre>
  $result = mysql_query($current_query);

  if ($result)
  { $ObjTBS = new clsTinyButStrong ;
    $ObjTBS->LoadTemplate("index.htm") ;
   
    $current_record = mysql_fetch_assoc($result);

    $ObjTBS->MergeBlock("record",$current_record);

    if ($debug==1) { $ObjTBS->MergeBlock("post",$_POST);};

    $ObjTBS->Show() ;
    //print_r($current_record);

  };
</pre>


The templates file 'index.htm' contains an 'onload' statement :
<pre>
  <P>[tbs_include.onload;file=[var.current_view_file]]</P>
/pre>

the variable named 'current_view_file' holds the name of the template where the 'record' block has to be merged.

But in this case the merging does'nt happen, for some strange reason I get the repetition of the template 21 times... (?)
Strange, the table selected by the query has 21 fields ...

I'm pretty sure the the array 'current_record' holds only 1 record, so I should see one record with the merging done.

Everything works fine with Mysql merging instead of Array merging :
<pre>
    $ObjTBS->MergeBlock("record",$cnx_id,$current_query);
</pre>
is OK.

But I would really like to do the merging through an array.

Is there something I am doing wrong ?
Any help would be greatly appreciated.

By the way TinyButStrong is really as great job.


By: Skrol29
Date: 2003-06-30
Time: 14:09

Re: Help needed with array merging

Hello Al,

I thing I know what happens.
They are two kind of array that TBS can merge with block.

Simple arrays, like:
[k0]=>v0
[k1]=>v1
...

And nested arrays, like:
[0] [k0]=>v0a ; [k1]=>v1a
[1] [k0]=>v0b ; [k1]=>v1b
...

Simple arrays are merged using the column names 'key' and 'val' which are keyword that represent the key and the value of each item of the array.

Nested arrays are merged using the column names k0,k1...

In your case you put a simple array. So there is a record for each item of the array. And no data is displayed because [record.key] and [record.val] are nor used the your template.

All should be goes well if you replace
$ObjTBS->MergeBlock("record",$current_record);
with
$ObjTBS->MergeBlock("record",array($current_record));
Then only one record will be merged.