The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Total Sum of Column
#1
Hey guys,

So I think I am having a bit of a blonde moment. In one of my database tables I have a column that is numbers, I want to query this table and get the sum of all the numbers in this column.

I'm having trouble with mysql_fetch_array / mysql_fetch_assoc. Is there another way userspice handles this?

Here's my code so far:

Code:
$usage = $db->query("SELECT SUM(month_usage) FROM devices");
Code:
$row = mysql_fetch_assoc($usage);
Code:
$sum = $row['month_usage'];

I think I am mixing up my queries because I am getting this error:

Quote:Warning: mysql_fetch_assoc() expects parameter 1 to be resource, object given in /#PATH#/dashboard.php on line 13

I have another version of this that uses mysql_fetch_array in a different manner, but that basically gives the same error.

Anyone got any ideas on where to go from here?
  Reply


Messages In This Thread
Total Sum of Column - by winterswolf - 11-29-2016, 11:56 PM
Total Sum of Column - by mudmin - 11-30-2016, 01:41 AM
Total Sum of Column - by winterswolf - 11-30-2016, 04:55 AM
Total Sum of Column - by mudmin - 12-01-2016, 03:43 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)