I have the below that works fine
$donations = $SQL->query(“SELECT money FROM amidon_donations
WHERE id
= ‘$id’”);
$row = $SQL->fetch_array($donations);
When I try to load this in array by using
$money[gross_price] it works fine
but when I add a sum to $donations = $SQL->query(“SELECT sum(money) FROM amidon_donations
WHERE id
= ‘$id’”);
It doesn’t display in a template using $row[money]
what am I doing wrong, I need the sum
SELECT SUM(money) AS money FROM…
1 Like
Where is the value for $id coming from?
Isn’t this the same question as Query using a sum ?
I thought the problem was different I think it is is the template that was causing the query not work
Yes and no.
When you
SELECT sum(money) FROM
the $row will have a “sum” field because that is what is SELECTed
So you could change the template code to use that.
IMHO it would be safer and more clear to do as felgall posted and use an AS to give the result field that name.
Either way, the SELECT in the query and the $row in the template need to be using the same name.
system
Closed
7
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.