我想通过添加所有progressDone
并将其除以完成的进度数来计算progressDone
的百分比。它不工作,我也得到错误
类型的资源(4)(mysql链接)
注意:类stdClass的对象无法转换为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;
答案 0 :(得分:1)
你的问题在这里
$online = mysql_fetch_object($result);
$total = done; //done from the sql statement
$current = $online;
mysql_fetch_object
返回一个对象。你不能像这样引用列。您需要将列作为对象的成员调用
$total = $online->done;
$current = $online->totall;