Undefined Index: And Array_Push

The MySQL query works and returns values, but when I try to use it in my code I get - Undefined index: amount. I thought the indexes would by amount and month as established in my query, but I’m doing something wrong. Any hints or answers would be great! Thanks

Error from the array_push:

Undefined index: amount

Calling the function:


The function:

	public static function getDirectorBarChartNumbers()  {

		//$returnArray = array(Donation::model()->findAll("is_processed = 1"));

		$returnArray = array();

		$pProcessed = Yii::app()->db->createCommand("SELECT SUM( `amount` ) AS 'amount', DATE_FORMAT( DATE, '%b %Y' ) AS 'month' "

													."FROM donation "

													."WHERE `is_processed` =1 "

													."GROUP BY MONTH( DATE ) ASC "

													."LIMIT 3 ");

		foreach ($pProcessed as $processed) {

			array_push($returnArray, array('amount'=>$processed['amount'], 'month'=>$processed['month']));


		return $returnArray;


You haven’t performed the query yet. Add ->queryAll() to the end of your createCommand() statement.

Thank you Keith, I added,

$results = $pProcessed->queryAll();

and it worked.