I have used global variables via tal:define="global ..." to keep track of the last value printed so I can do sub-total break:

Defore the loop:
   <tal:block tal:define="global lastAgreement string:x" />

During the loop:
   <tal:block tal:condition="php:oneRow['AGREEMENT_UID']!=lastAgreement">
       ...
   </tal:block>
   <tal:block tal:define="global lastAgreement oneRow/AGREEMENT_UID" />


[EMAIL PROTECTED] wrote:
Send PHPTAL mailing list submissions to
        phptal@lists.motion-twin.com

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.motion-twin.com/mailman/listinfo/phptal
or, via email, send a message with subject or body 'help' to
        [EMAIL PROTECTED]

You can reach the person managing the list at
        [EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of PHPTAL digest..."


Today's Topics:

   1. Table column with difference value (Krzysztof Zaleski)
   2. Re: Table column with difference value (Krzysztof Sikorski)
   3. Re: Table column with difference value ( Iv?n -DrSlump- Montes )
   4. Re: Table column with difference value (Levi Stanley)


----------------------------------------------------------------------

Message: 1
Date: Sun, 23 Mar 2008 23:02:58 +0100
From: "Krzysztof Zaleski" <[EMAIL PROTECTED]>
Subject: [PHPTAL] Table column with difference value
To: phptal@lists.motion-twin.com
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="utf-8"

Hi,

Let's assume I have a table (generated from DB) with 3 columns with daily
receipts from three shops. Fourth column is a sum of all three values (sum
is calculated by SQL query). Now, I would like to add next column showing
the difference between the sum of current day, and the value from previous
day. I tried using tal:define in various ways, but I either get the message
that some variable is redefined twice, or some variable definition is
missing. From my tests it seems that I cannot accomplish this task with
tal:define. If I could do something like tal:php :-) it would be perfect.
The whole idea is rather simple, but I don't know how to store previous
value from one row iteration to another. Any ideas?

Rgrds,
Krzysztof
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://lists.motion-twin.com/pipermail/phptal/attachments/20080323/ac94b488/attachment-0001.htm

------------------------------

Message: 2
Date: Sun, 23 Mar 2008 23:19:38 +0100
From: "Krzysztof Sikorski" <[EMAIL PROTECTED]>
Subject: Re: [PHPTAL] Table column with difference value
To: "Template Attribute Language for PHP"
        <phptal@lists.motion-twin.com>
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=UTF-8

If I could do something like tal:php :-) it would be perfect.
Your can use php code in expressions:
http://phptal.motion-twin.com/manual/en/split/ar05s07.html#tales-php



------------------------------

Message: 3
Date: Sun, 23 Mar 2008 23:55:34 +0100
From: " Iv?n -DrSlump- Montes " <[EMAIL PROTECTED]>
Subject: Re: [PHPTAL] Table column with difference value
To: "Template Attribute Language for PHP"
        <phptal@lists.motion-twin.com>
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1

I haven't tried it but perhaps something like this can give you the result:

<tr tal:repeat="item data">
  <td tal:content="item/total">Total</td>
  <td tal:content="php: lastTotal">Last Total</td>
  <?php $ctx->lastTotal = $ctx->item['total']; ?>
</tr>

or

<tr tal:repeat="item data">
  <td tal:content="item/total">Total</td>
  <td>
    <?php
        echo $lastTotal;
        $lastTotal = $ctx->item['total'];
    ?>
  </td>
</tr>

ivan

On Sun, Mar 23, 2008 at 11:19 PM, Krzysztof Sikorski
<[EMAIL PROTECTED]> wrote:
If I could do something like tal:php :-) it would be perfect.
 Your can use php code in expressions:
 http://phptal.motion-twin.com/manual/en/split/ar05s07.html#tales-php

 _______________________________________________
 PHPTAL mailing list
 PHPTAL@lists.motion-twin.com
 http://lists.motion-twin.com/mailman/listinfo/phptal




------------------------------

Message: 4
Date: Sun, 23 Mar 2008 19:54:21 -0400
From: "Levi Stanley" <[EMAIL PROTECTED]>
Subject: Re: [PHPTAL] Table column with difference value
To: "Template Attribute Language for PHP"
        <phptal@lists.motion-twin.com>
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"

Why not just do all of it in SQL?  Or you can iterate everything into an
array, before you push it to the presentation layer.

...

$data = array();
while($row = $result->doSelect($criteria)){
  array_push($data, array( '3-shop-sum' => $row['1st-shop'], '2nd-shop' =>
$row['2nd-shop'], '3rd-shop' => $row['3rd-shop'], '3-shop-sum' =>
$row['3-shop-sum'], 'previous-day' => $previous);
  $previous = $row['3-shop-sum'];
}

$template->set('list', $data);

...

On Sun, Mar 23, 2008 at 6:02 PM, Krzysztof Zaleski <[EMAIL PROTECTED]>
wrote:

Hi,

Let's assume I have a table (generated from DB) with 3 columns with daily
receipts from three shops. Fourth column is a sum of all three values (sum
is calculated by SQL query). Now, I would like to add next column showing
the difference between the sum of current day, and the value from previous
day. I tried using tal:define in various ways, but I either get the message
that some variable is redefined twice, or some variable definition is
missing. From my tests it seems that I cannot accomplish this task with
tal:define. If I could do something like tal:php :-) it would be perfect.
The whole idea is rather simple, but I don't know how to store previous
value from one row iteration to another. Any ideas?

Rgrds,
Krzysztof

_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://lists.motion-twin.com/pipermail/phptal/attachments/20080324/3a1ab839/attachment-0001.htm

------------------------------

_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


End of PHPTAL Digest, Vol 37, Issue 9
*************************************


_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to