views:

74

answers:

2

I have the following query that extends from Zend_DB_Table_Abstract

$select = $this->select()
            ->from('expense_details',
             array('SUM(expense_details_amount) AS total'))
        ->where('YEAR(expense_details_date) = ?', '2010')
            ->where('MONTH(expense_details_date) = ?', '01')
            ->where('expense_details_linkemail = ?', '[email protected]');

However it returning a NULL value despite its "equivalent" returning the desired value

SELECT SUM(expense_details_amount) AS total FROM expense_details
WHERE 
YEAR(expense_details_date) = '2010'                     
AND MONTH(expense_details_date) = '01'
AND expense_details_linkemail = '[email protected]'

Is my Zend_DB_Table construct above correct?

A: 

One thing that might be a problem is the 'AS' statement within this string literal.

array('SUM(expense_details_amount) AS total'))

Try changing it to this:

array('total' => 'SUM(expense_details_amount)'))

I believe this is how Zend_Db_Select handles AS.

Antonio Haley
A: 

After searching hard for a solution I found where the problem is.

I changed

$value = $this->fetchAll($select); 
$data[] = $value->total; 

to

$value = $this->fetchRow($select); 
$data[] = $value->total;
davykiash