Tomasz Ignatiuk wrote:
> Hello
> 
> I try to use Propel SUM and GROUP BY. It works as it should. The only
> problem is with showing results. I use this in action:
> 
> $cu = new Criteria();
> $cu->clearSelectColumns();
> $cu->add(DokumentLinikiPeer::DOKUMENT_ID, $this->getUser()-
>> getAttribute('dokument_id'));
> $cu->addSelectColumn('SUM(' . DokumentLinikiPeer::KWOTA_NETTO . ') AS
> nettosum');
> $cu->addSelectColumn('SUM(' . DokumentLinikiPeer::KWOTA_BRUTTO . ') AS
> bruttosum');
> $cu->addGroupByColumn(DokumentLinikiPeer::STAWKI_VAT);
> $this->sumy = DokumentLinikiPeer::doSelectStmt($cu);
> 
> And in template:
> 
>               <?php while ($row = $sumy->fetch(PDO::FETCH_ASSOC)) { ?>
>                 <tr>
>                   <td><?php echo $row['nettosuma']; ?></td>
>                   <td><?php echo $row['bruttosuma']; ?></td>
>                 </tr>
>               <?php } ?>
> 
> It also works but in addition to this I want to show a value of a
> column by witch results where grouped by: STAWKI_VAT. So I will have:
> 
> nettosum 100
> brutto sum 122
> vat for this sum: 22
> 
> How to do this?

Ask the database:

$cu->addSelectColumn('SUM(' . DokumentLinikiPeer::KWOTA_NETTO . '+' . 
DokumentLinikiPeer::KWOTA_BRUTTO . ') AS
vat for this sum');

You could do the addition in the template, but that would violate MVC 
principles.

David

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to