Symfony Framework
How to do SUM with Propel
http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel/
$c->addSelectColumn(‘sum(‘.dbTimeBlockPeer::TOTAL.’) as total’);
$rs = dbTimeBlockPeer::doSelectRS($c);
while ($rs->next()) { $total = $rs->getInt(1); }
And a real world example from symfony users mailing list (Symfony 1.2):
ACTION:
$cu = new Criteria();
$cu->clearSelectColumns();
$cu->add(DokumentLinikiPeer::DOKUMENT_ID, $this->getUser()->getAttribute(‘dokument_id’));
$cu->addSelectColumn(DokumentLinikiPeer::STAWKI_VAT);$cu->addSelectColumn(‘sum(‘.DokumentLinikiPeer::KWOTA_NETTO.’) as
SumOfNetto’);$cu->addSelectColumn(‘sum(‘.DokumentLinikiPeer::KWOTA_BRUTTO.’) as
SumOfBrutto’);$cu->addGroupByColumn(DokumentLinikiPeer::STAWKI_VAT);
$sumy = DokumentLinikiPeer::doSelectStmt($cu);
$total = array();
while ($row = $sumy->fetch(PDO::FETCH_NUM)) {
$total[] = array(
‘vat’ => StawkiVatPeer::retrieveByPK($row[0]), // VAT
‘netto’ => $row[1], // SumOfNetto
‘brutto’ => $row[2], // SumOfBrutto
);}
TEMPLATE:
<?php foreach($sumy as $suma): ?>
<tr>
<td><?php echo $suma['vat']; ?></td>
<td><?php echo $suma['netto']; ?></td>
<td><?php echo $suma['brutto']; ?></td>
</tr>
<?php endforeach ?>
Tagged propel, Symfony Resources

JevonApril 29, 2009 at 2:34 pm
Alternatively,
$count = MyPeer::doCount(new Criteria());
JevonApril 29, 2009 at 2:34 pm
Oops, just realised yours was for SUM not COUNT :-)
seo vpsApril 9, 2013 at 3:07 am
Improve your google rank today check this out! http://goo.gl/YzNKa