It is the table cell “betrag” I need to sum at the end. I found $query->sum()in the docs and $query->result() but I don’t have an idea what to do with it and which is the right one.
A much more “Kirby” alternative, indeed! That would be my preference (and I was wrong with my assumption above - learning something new here every day).
Agreed; semi-wrong, then …I once again was blissfully ignorant of the sheer endless utility of pluck(), which appears to be the answer to everything. A bit like 42.
I already display a table with numbers in it, which I pull from another page (see: Display content from page on homepage). Now I would like to display the sum in td as well.
we create a flat array of all betrag entries, giving us an array like this:
Array
(
[0] => 2.50
[1] => 2.80
)
The array_sum() method then adds up all elements in the array. Internally, it iterates through the elements and sums them up in a similar way as the solution provided by @sebastiangreger, but much faster.
Finally, after the colon comes the part that is rendered if page('spenden') returns nothing: we echo noch nix or an empty string.