1

I had created model donation to save donation information and now i want to display total amount of donation to be shown with all the other field

my table is as follows

--------------------------- name address phone amount test abc 454545 55 test2 pqr 83294 10 test abc 31286 50 and desires output would be like

--------------------------- name address phone amount test abc 454545 105 test2 pqr 83294 10

i'm trying to put code

$testmodel = Mage::getModel('donation/donation') ->getCollection() ->getSelect()->group('name') ->addExpressionAttributeToSelect('SUM({{amount}})', 'amount');

but it can't work.

2

I just used this query to get desired output

$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('core_read');
$categoryProductTable=$read->getTableName('donation');
$select = $read->select()->from(array('cp'=>$categoryProductTable),array('sum(amount) as sum', 'name', 'address' ,'phone'));
$select->group('name');
$products=$read->fetchAll($select);
1

The method addExpressionAttributeToSelect is only available as a method for the resource model. Since you've appended it after getSelect it wont be able to find the method.

$testmodel = Mage::getModel('donation/donation')->getCollection()
   ->addExpressionAttributeToSelect('SUM(`amount`)', 'amount')
   ->getSelect()->group('name');

Try above, that should work better

  • it didn't work I have to perform it using Zend Query – Paras Arora Oct 14 '15 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.