Categories > TinyButStrong general >

Conditional display of table cell (td)

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Marcus
Date: 2007-06-04
Time: 15:48

Conditional display of table cell (td)

Hi,

I display the result of a MySQL query in a table using merging
of blocks (works fine).
However in one particular cell I need to display just the content
of a variable or conditioanl some additional html around it.
I used onshow, but this is veeery slow. Is there another and FASTER
approach?

In my template the code for the cell looks like this:
<p>[onshow; block=td; when [blk1.posflag]=0][blk1.summary]</p>
</td>
<td>
<p>[onshow; blk1.pos][block=td; when [blk1.posflag]=1] <a class="tooltip" href="#">more<span>[blk1.summary]</span></a></p>
</td>

This means:
if posflag = 0 I want just display blk1.summary in that cell
if posflag = 1 I need to display additional stuff
By: Skrol29
Date: 2007-06-04
Time: 21:16

Re: Conditional display of table cell (td)

Hi,

Your snippet
   [onshow; blk1.pos][block=td; when [blk1.posflag]=1]
is not correct, and I'm not sur to understand well what you need precisly.
Can you fix this line in order to precise your question ?
By: Marcus
Date: 2007-06-05
Time: 09:10

Re: Conditional display of table cell (td)

Hi Skrol29,

What I want to do (basically) is:
I run an MySQL query and then use MergeBlock and Show to display
the result of the query in a (html) template. That works fine.
NB: One of the fields from the query is called 'pos', one 'summary'
and one 'posflag' (posflag can be 0 or 1).

The table has several rows and 5 columns. So the table looks like
this:
+------+------+------+------+------+
+        +        +  C3 +        +        +
+------+------+------+------+------+
+        +        +  C3 +        +        +
+------+------+------+------+------+
+        +        +  C3 +        +        +
+------+------+------+------+------+
+        +        +  C3 +        +        +
+------+------+------+------+------+
.
.
.

C3 is made of <td>bla, bla</td> in HTML. Depending on the value
of 'posflag' (which comes from the MySQL query) I want to display
for C3 alternative content:

If posflag = 0 then C3 should be look like this:
<td><p>[blk1.summary]</p></td>

If posflag = 1 then C3 should be look like this:
<td><p>[blk1.pos]<a class="tooltip" href="#">more<span>[blk1.summary]</span></a></p></td>

blk1 is the block I pass to the HTML template using MergeBlock ($TBS->MergeBlock('blk1, blk2', $link_id, $query); and Show().

.summary, .pos and .posflag are fields returned by the MySQL query.

In short: depending on the content of posflag I need either content A or content B in a particular cell of a table, where posflag can change
from row to row (depending the result of an MySQL query).

Hth,
thanks so far,
rgds,
Marcus























By: Marcus
Date: 2007-07-09
Time: 10:41

Re: Conditional display of table cell (td)

nobody there to answer that question, please??
By: Skrol29
Date: 2007-07-09
Time: 14:42

Re: Conditional display of table cell (td)

Hi Marcus,

Sorry, I missed your previous message.

There are many solutions to do what you need. The solution with [onshow] is slow because it has to scan for lot of conditional blocks after the merge of the "blk1". It is better to do it in the flow.

One solution is to use conditional sections for the block. For this solution 
to have to copy the entire <tr>, and then chnage only the <td> id the copy. TBS manage conditional sections quickly.

Another solution is to place parts to hide or display inside HTML tags, and to display or delete the tags with parameter "magnet".
<p>
  [blk1.posflag;if [val]=0;then ''; else ' ';magnet=p]
  [blk1.summary]
</p>
<p>
  [blk1.posflag;if [val]=1;then ''; else ' ';magnet=p]
  <a class="tooltip" href="#">more<span>[blk1.summary]</span></a>
</p>

TBS can process this faster you use a "ondata" function to create a new column that has vlaues '' or ' ' depending to column posflag.



By: Marcus
Date: 2007-07-09
Time: 18:41

Re: Conditional display of table cell (td)

Hi Skrol29,

Thanks for looking into this once more. This helped a lot!!
The final solution (that works :-) is as follows:
<p>[blk1.pos] <a class="tooltip" href="#">more<span>[blk1.summary][blk1.posflag;if [val]=0;then ''; else '</span>';magnet=a]</a></p>