Hi guys. I have a code here wherein it counts how many total payment is made. My question is, how to find the total paid amount? when im using $payment = $payment_tbl->sumOf("paid_amount");
but im getting an error Unknown method “sumOf” BadMethodCallException
sumOf is a collection function. You can use it on the results of a query, like $payment = $payment->sumOf('paid_amount'); This runs as a loop over the results in PHP. Alternately, there’s a way to execute the sum function directly in MySQL, if that’s the only thing you’re interested in; it can range from an insignificant amount faster to a whole lot faster to the only feasible method, depending on how many rows you have in your database.
can you provide some codesnippets how your select and set method looks like ? … and how you output in your template … if possible you could check with debug($payment); in the controller the content
try also :
$payments = TableRegistry::getTableLocator()->get(‘Payments’);
i am asking myself if your table really is named „Payment“ and not Payments … but if you refer to a wrong table, you should an error … as said a bit more code from you would help a lot