symfony 1.4 propel 1.6 : sum [英] symfony 1.4 propel 1.6 : sum
问题描述
我正在尝试获取 propel 中的列总和.我的代码
I'm trying to get a sum of columns in propel. My code
$c = new Criteria();
$c->add(valuePeer::OWNER_ID, $this->getId());
$c->addSelectColumn('SUM(' . valuePeer::VALUE . ') as total');
$c->addGroupByColumn(valuePeer::VALUE);
$sum = valuePeer::DoSelect($c);
打印出$sum
什么都不返回(甚至不是一个空对象).我得到的只是 Notice: Undefined offset: 1 in/.../lib/model/om/BaseValue.php on line 203 注意:Undefined offset: 2 in/.../lib/model/om/BaseValue.php 第 204 行
printing out $sum
returns nothing (not even an empty object). all i get is Notice: Undefined offset: 1 in /.../lib/model/om/BaseValue.php on line 203 Notice: Undefined offset: 2 in /.../lib/model/om/BaseValue.php on line 204
我按照建议使用 ::DoSelectRS($c)
尝试了这种方法 here 和其他多个讨论,但我收到一个错误:致命错误:调用/.../lib/model/Restauracia.php 中未定义的方法 ValuePeer::DoSelectRS()在第 39 行
.
I tried this approach with ::DoSelectRS($c)
as suggested here and multiple other discussions but i get an error : Fatal error: Call to undefined method ValuePeer::DoSelectRS() in /.../lib/model/Restauracia.php on line 39
.
谁能告诉我什么是正确的方法呢?
Can anyone please tell me what is the right approach on this then?
推荐答案
我刚刚找到了这个解决方案.它像我需要的那样工作.
i just found this solution. it works like i needed.
$c = new Criteria();
$c->clearSelectColumns();
$c->add(valuePeer::OWNER_ID, $this->getId());
$c->addSelectColumn('SUM(' . valuePeer::VALUE . ') as total');
//$c->addGroupByColumn(valuePeer::VALUE);
$sum = valuePeer::DoSelectStmt($c)->fetchAll(PDO::FETCH_COLUMN,0);
$sum = $sum[0];
这篇关于symfony 1.4 propel 1.6 : sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!