誰かが私が間違っていることのヒントを教えてもらえますか?
public function getPaymentSumByTypeAndProject($project_id,$type) {
$type = (int) $type;
$project_id = (int) $project_id;
$rowset = $this->tableGateway->select(array('total_amount' => new Expression('SUM(payment.amount)')))->where(array('type' => $type, 'project_id' => $project_id));
$row = $rowset->toArray();
if (!$row) {
throw new \Exception("Busted :/");
}
return $rowset;
}
同じクエリを作成したい:
SELECT SUM(amount) FROM payment WHERE type='$type' AND project_id ='$project_id';
編集:私は小さな進歩を遂げました。列全体を合計する方法を見つけました
public function getPaymentSumByTypeAndProject($project_id, $type) {
$type = (int) $type;
$project_id = (int) $project_id;
$resultSet = $this->tableGateway->select(function (Select $select) {
$select->columns(array(new \Zend\Db\Sql\Expression('SUM(amount) as amount')))->where('type="0"');
});
return $resultSet;
誰かが条件を追加する方法を理解するのを手伝ってくれるかもしれません: "WHERE type='$type' AND project_id='$project_id'" ?