The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Column Sum - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23) +--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26) +--- Thread: Column Sum (/showthread.php?tid=818) |
Column Sum - matt - 11-01-2017 Im trying to add up the values of a single column but failing..... <?php $query = $db->query("SELECT SUM (sendout) from sendouts"); $count = $db->count(); echo $count; var_dump($count); ?> Column Sum - Brandin - 11-01-2017 Count gives you the number of rows returned in your query. Use $db->first(); to return the first row which is all you will have given you are only selecting the sum. Also, after this, you will need to have the column you want to output. I would: -Change your select to be SUM(sendout) AS Total (or whatever you want to call it) -Make your $count = to $db->first()->Total; Then you can echo it Column Sum - mudmin - 11-01-2017 If you're still having a problem with this and getting your query right, you can do something like this. Code: $count = 0; Code: $query = $db->query("SELECT sendout FROM sendouts")->results(); Code: foreach ($q as $sum){ Code: $count = $count + $sum->sendout; Code: } Code: echo $count; It's important to establish Code: $count = 0 |