By: Rudy
Date: 2010-02-24
Time: 12:13
|
Merge multilanguage table
Hello,
I'm stuck with a TBS-block definition to display a multilanguage table.
What is the best way to merge this data (from a select):
$charges[] = array('id'=>1, 'price'=>10.0, 'language'=>'en', 'description'=>'Lorem 1 en');
$charges[] = array('id'=>1, 'price'=>10.0, 'language'=>'fr', 'description'=>'Ipsum 1 fr');
$charges[] = array('id'=>1, 'price'=>10.0, 'language'=>'it', 'description'=>'Dolor 1 it');
$charges[] = array('id'=>2, 'price'=>8.0, 'language'=>'en', 'description'=>'Lorem 2 en');
$charges[] = array('id'=>2, 'price'=>8.0, 'language'=>'fr', 'description'=>'Ipsum 2 fr');
$charges[] = array('id'=>2, 'price'=>8.0, 'language'=>'it', 'description'=>'Dolor 2 it');
|
into this:
<table>
<tr>
<td>1</td>
<td>10.0</td>
<td>
<input lang="en" value="Lorem 1 en" />
<input lang="fr" value="Ipsum 1 fr" />
<input lang="it" value="Dolor 1 it" />
<td>
</tr>
<tr>
<td>2</td>
<td>8.0</td>
<td>
<input lang="en" value="Lorem 2 en" />
<input lang="fr" value="Ipsum 2 fr" />
<input lang="it" value="Dolor 2 it" />
<td>
</tr>
</table>
|
What I try always seems to get to complicated for this easy task. One possibility would be to use dynamic subblocks and use 2 queries:
<table>
<tr>[charges;block=tr]
<td>[charges.id]</td>
<td>[charges.price]</td>
<td>
<input lang="[charges_language.language]" value="[charges_language.description]" />[charges_language;block=_;p1=[charges.id]]
<td>
</tr>
</table>
|
You can probably immagine how the queries would look like knowing the above data. But this approach would produce many queries for displaying this table - is this really needed? I get all the data I need from a view within one select. I tried with automatic subblock but either I'm doing wrong or it's not possible this way.
What's the best - less expensive - way to merge this?
Any help is kindly appreciated.
Rudy
|
By: TomH
Date: 2010-02-24
Time: 13:37
|
Re: Merge multilanguage table
Rudy
I would try to use the headergrp or parentgrp methods native in TBS
Look at http://www.tinybutstrong.com/examples.php and select the "Groupings" example for a detailed example that looks to be a match for what you describe.
HTH,
|
By: Skrol29
Date: 2010-02-24
Time: 13:45
|
Re: Merge multilanguage table
Hi Rudy,
You can try this:
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td bgcolor="#CCCCCC">Id</td>
<td bgcolor="#CCCCCC">Price</td>
<td bgcolor="#CCCCCC">Description</td>
</tr>
<tr>
<td>[charges.id;block=tr;parentgrp=id]</td>
<td>[charges.price]</td>
<td><span><input lang="[charges.language;block=span]" value="[charges.description]" /> </span></td>
</tr>
</table>
|
|
By: Rudy
Date: 2010-02-24
Time: 14:13
|
Re: Merge multilanguage table
Hi,
thank you both for your quick answers! I was thinking of grouping too, but could not figure it out in this case.
The parentgrp example works like a charm. Being a minimalist, I even could spare the span :) I did not know parentgrp worked with line-blocks. Well, that's great!
<table>
<tr>
<td>Id</td>
<td>Price</td>
<td>Description</td>
</tr>
<tr>
<td>[charges.id;block=tr;parentgrp=id]</td>
<td>[charges.price]</td>
<td>
<input lang="[charges.language;block=_]" value="[charges.description]" />
</td>
</tr>
</table>
|
You helped me really much, thank you.
Rudy
|
By: Rudy
Date: 2010-03-02
Time: 09:41
|
Re: Merge multilanguage table
Hello,
If life were easy, it wouldn't be hard :) Lets get one level up... is it possible to have two (or more) language dependent columns in the data? Like:
$charges[] = array('id'=>1, 'price'=>10.0, 'language'=>'en', 'description'=>'T 1 en', 'description'=>'D 1 en');
$charges[] = array('id'=>1, 'price'=>10.0, 'language'=>'fr', 'description'=>'T 1 fr', 'description'=>'D 1 fr');
$charges[] = array('id'=>1, 'price'=>10.0, 'language'=>'it', 'description'=>'T 1 it', 'description'=>'D 1 it');
$charges[] = array('id'=>2, 'price'=>8.0, 'language'=>'en', 'description'=>'T 2 en', 'description'=>'D 2 en');
$charges[] = array('id'=>2, 'price'=>8.0, 'language'=>'fr', 'description'=>'T 2 fr', 'description'=>'D 2 fr');
$charges[] = array('id'=>2, 'price'=>8.0, 'language'=>'it', 'description'=>'T 2 it', 'description'=>'D 2 it');
|
and merge just one to get the following:
<table>
<tr>
<td>1</td>
<td>10.0</td>
<td class="title">
<input lang="en" value="T 1 en" />
<input lang="fr" value="T 1 fr" />
<input lang="it" value="T 1 it" />
</td>
<td class="description">
<input lang="en" value="D 1 en" />
<input lang="fr" value="D 1 fr" />
<input lang="it" value="D 1 it" />
</td>
</tr>
<tr>
<td>2</td>
<td>8.0</td>
<td class="title">
<input lang="en" value="T 1 en" />
<input lang="fr" value="T 1 fr" />
<input lang="it" value="T 1 it" />
</td>
<td class="description">
<input lang="en" value="D 1 en" />
<input lang="fr" value="D 1 fr" />
<input lang="it" value="D 1 it" />
</td>
</tr>
</table>
|
I tried several combination with serial (which I never used before), but it seems not the right solution for this, at least the results are more far away than the simple group which "eats" all description columns for every group except the last one:
<table>
<tr>
<td>Id</td>
<td>Price</td>
<td>Description</td>
</tr>
<tr>
<td>[charges.id;block=tr;parentgrp=id]</td>
<td>[charges.price]</td>
<td class="title">
<input lang="[charges.language;block=_;p1]" value="[charges.title]" />
</td>
<td class="description">
<input lang="[charges.language;block=_;p1]" value="[charges.description]" />
</td>
</tr>
</table> |
The result with this template is:
<table>
<tr>
<td>Id</td>
<td>Price</td>
<td>Description</td>
</tr>
<tr>
<td>1</td>
<td>10</td>
<td class="title">
<input lang="en" value="T 1 en" />
<input lang="fr" value="T 1 fr" />
<input lang="it" value="T 1 it" />
</td>
<td class="description">
<input lang="it" value="D 1 it" />
</td>
</tr><tr>
<td>2</td>
<td>8</td>
<td class="title">
<input lang="en" value="T 2 en" />
<input lang="fr" value="T 2 fr" />
<input lang="it" value="T 2 it" />
</td>
<td class="description">
<input lang="it" value="D 2 it" />
</td>
</tr>
</table> |
Were do I go wrong? Are the dynamic queries - I try to avoid as best as I can for better perfomance - the only solution in this case?
Thanks again, I really appreciate your help.
Rudy
|
By: Rudy
Date: 2010-03-02
Time: 09:42
|
Re: Merge multilanguage table
Sorry, here is the right data for the previous example:
$charges[] = array('id'=>1, 'price'=>10.0, 'language'=>'en', 'title'=>'T 1 en', 'description'=>'D 1 en');
$charges[] = array('id'=>1, 'price'=>10.0, 'language'=>'fr', 'title'=>'T 1 fr', 'description'=>'D 1 fr');
$charges[] = array('id'=>1, 'price'=>10.0, 'language'=>'it', 'title'=>'T 1 it', 'description'=>'D 1 it');
$charges[] = array('id'=>2, 'price'=>8.0, 'language'=>'en', 'title'=>'T 2 en', 'description'=>'D 2 en');
$charges[] = array('id'=>2, 'price'=>8.0, 'language'=>'fr', 'title'=>'T 2 fr', 'description'=>'D 2 fr');
$charges[] = array('id'=>2, 'price'=>8.0, 'language'=>'it', 'title'=>'T 2 it', 'description'=>'D 2 it');
|
|
By: TomH
Date: 2010-03-02
Time: 14:29
|
Re: Merge multilanguage table
Rudy
The children of the parent need to be segregated into a separate 'block'
something like this
<table summary="" border=1>
<tr>
<td>Id</td>
<td>Price</td>
<td>Description</td>
</tr>
<tr>
<td>[charges.id;block=tr;parentgrp=id]</td>
<td>[charges.price]</td>
<td class="title">
<table summary="">
<tr>
<td><input lang="[charges.language;block=tr]" value="[charges.title]" /></td>
<td><input lang="[charges.language;]" value="[charges.title]" /></td>
</tr>
</table>
</td></tr>
</table> |
This snippet does work with your data
HTH,
|
By: TomH
Date: 2010-03-02
Time: 14:35
|
Re: Merge multilanguage table
Sorry... I meant to post
<table summary="">
<tr>
<td><input lang="[charges.language;block=tr]" value="[charges.title]" /></td>
<td><input lang="[charges.language;]" value="[charges.description]" /></td>
</tr>
</table> |
|
By: Rudy
Date: 2010-03-03
Time: 09:22
|
Re: Merge multilanguage table
Hi TomH,
that's it, thanks for your kind help.
Bye
Rudy
|
By: TomH
Date: 2010-03-03
Time: 23:31
|
Re: Merge multilanguage table
I think that's really thanks to Skrol29 needed - his 'span' tag did the same as my row inside a table.
The block defined for the parentgrp has to wrap around the block def for the children - so TBS knows where to do the repeats within the parent block.
Glad you got it now.
|
|
Posting in progress.
Please wait...
|