0

I want to calculate the percentage of progressDone by adding all progressDone and dividing it with the numbers of progress done. it is not working and i am also getting error

resource(4) of type (mysql link)
Notice: Object of class stdClass could not be converted to int

$query = "SELECT SUM(progressDone) AS totall, COUNT(progressDone) AS done FROM  progress, progressType WHERE progress.projectID='$projectID' AND progress.progressTypeID='1'";
$result = mysql_query($query, $db)
or die("Query failed: ".mysql_error()." Actual query: ".$query);
$online = mysql_fetch_object($result);
$total = done; //done from the sql statement 
$current = $online;
$percent = (($current/$total) * 100);
$percentNot = 100 - $percent;
Machavity
  • 30,841
  • 27
  • 92
  • 100
Seeruttun Kervin
  • 33
  • 1
  • 1
  • 9
  • 2
    You are calling `mysql_fetch_object`. Why would you think you could use `$online` as an integer? It is an _object_ – Jeff Lambert Mar 02 '16 at 16:00
  • You need to [stop using mysql_ functions, as they are no longer in PHP](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Machavity Mar 02 '16 at 16:13

1 Answers1

1

Your problem is here

$online = mysql_fetch_object($result);
$total = done; //done from the sql statement 
$current = $online;

mysql_fetch_object returns an object. You can't just reference the columns like this. You need to call the columns as members of the object

$total = $online->done;
$current = $online->totall;
Machavity
  • 30,841
  • 27
  • 92
  • 100