How To Retrieve The Sum Data From The Query

I new to yii ! This my Action below when i try to print the SUM value it printing as( NULL )

plesae Help


public function actionNgoshare()

	{

	

	 Yii::app()->db

    ->createCommand("SELECT SUM(ngo_share) as `sum` FROM `tbl_orders` WHERE `cause`=':cause_name'")

    ->bindValues(array(':cause_name' => $_REQUEST['casue']))

    ->queryall();

    

    var_dump($sumPrice[0]['sum']);

		

	}

Firstly, ‘cause’ is misspelt here:


$_REQUEST['casue']

Secondly, bound parameters shouldn’t be surrounded by quotes:




"SELECT SUM(ngo_share) as `sum` FROM `tbl_orders` WHERE `cause`=':cause_name'"



should be:




"SELECT SUM(ngo_share) as `sum` FROM `tbl_orders` WHERE `cause`=:cause_name"



See if fixing either of those issues resolves the problem.

Still its returning NULL

Okay, try to debug it. What is the result of running this query instead?




"SELECT * FROM `tbl_orders` WHERE `cause`=:cause_name"



Also, I think this syntax may be wrong:


SELECT SUM(ngo_share) as `sum`

Try using standard quotes instead of backticks around sum.


SELECT SUM(ngo_share) as 'sum'

Thanks for the reply but still the same issues

For this too the same is coming

You’re not assigning the query result to anything.