11-29-2016, 11:56 PM
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:
I think I am mixing up my queries because I am getting this error:
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?
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?