navinjoseph
(Navinperiyanayagam Joseph)
August 26, 2014, 12:11pm
1
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']);
}
Keith
(Kburton)
August 26, 2014, 12:19pm
2
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.
Keith
(Kburton)
August 26, 2014, 12:33pm
4
Okay, try to debug it. What is the result of running this query instead?
"SELECT * FROM `tbl_orders` WHERE `cause`=:cause_name"
Keith
(Kburton)
August 26, 2014, 12:35pm
5
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'
navinjoseph
(Navinperiyanayagam Joseph)
August 26, 2014, 12:43pm
6
Keith:
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
navinjoseph
(Navinperiyanayagam Joseph)
August 26, 2014, 12:45pm
7
Keith:
Okay, try to debug it. What is the result of running this query instead?
"SELECT * FROM `tbl_orders` WHERE `cause`=:cause_name"
For this too the same is coming
Keith
(Kburton)
August 26, 2014, 1:48pm
8
You’re not assigning the query result to anything.