【发布时间】:2019-09-20 20:36:00
【问题描述】:
我尝试创建圆圈并从数据库中获取数据。但它不显示值,它打印绑定。
function circle()
{
$sql = "SELECT count(projects.id) AS count, projects.status as status
FROM user_projects
INNER JOIN projects ON projects.id = user_projects.project_id
WHERE user_projects.user_id = :user_id
AND projects.workspace = :current_workspace
GROUP BY projects.status";
$stmt = $this->db->prepare($sql);
$stmt->execute(array(':user_id' => $this->id, ':current_workspace' => $this->userinfo['current_workspace']));
//$stmt->debugDumpParams();
$projectProcess = $stmt->fetch(PDO::FETCH_OBJ);
//print_r($projectProcess);
$total = $this->totalProjects();
$arrProcessLable= [];
$arrProcessPer = [];
foreach ($projectProcess as $lable => $process){
$arrProcessLable[]= $lable;
$arrProcessPer[] = round(($process*100)/$total,2);
}
$arrProcessClass = ['text-success','text-primary','text-danger'];
return ['a' => $arrProcessLable, 'b' => $arrProcessPer, 'c' => $arrProcessClass];
}
数组打印“计数”而不是 6 之类的值。 它应该打印 6 个 project.id 计数。
同样,它打印“状态”,不像“正在进行”或“保持”,“完成” 它应该打印 6 个“正在进行”的项目
艾瑞:
Array
(
[a] => Array
(
[0] => count
[1] => status
)
[b] => Array
(
[0] => 100
[1] => 0
)
[c] => Array
(
[0] => text-success
[1] => text-primary
[2] => text-danger
)
)
【问题讨论】:
-
您能多解释一下这部分吗? “它不显示值,它打印绑定”是什么意思。?
-
@Dharman 它应该是 array( [a] => array ( [0] => 6 [1] => "Ongoing"...
-
那么你的foreach循环的目的是什么?只需返回不带循环的原始
$projectProcess。