gpt4 book ai didi

php - 如何查询多个变量以在 Codeigniter 的 View 中显示

转载 作者:行者123 更新时间:2023-11-29 16:21:28 25 4
gpt4 key购买 nike

我有一个使用 Codeigniter 进行编码的小项目,我只是停留在查询要在 View 中显示的特定列的总数。以下是我遇到困难的一些代码:

型号:

function get_dailyprob()
{
$date = date('d-m-Y');
$q1 = $this->db->select('client')->like('created_at', $date)->group_by('client')->get('histprob')->result();
$q2 = $this->db->like('created_at', $date)->count_all_results('histprob'); //HERE I HAVE NO IDEA HOW TO GET A TOTAL COUNT OF EACH ROWS THAT ALREADY GROUPED BY COLUMN client
return array('dp_client' => $q1, 'dp_count' => $q2);
}

Controller :

$data['dailyprobs'] = $this->skejuler_m->get_dailyprob();

查看:

<table class="table table-hover">
<?php if ($dailyprobs['dp_count'] > 0) {
foreach ($dailyprobs['dp_client'] as $dpc): ?>
<tr>
<td><?php echo $dpc->client; ?></td>
<td><span style="font-size:16px" class="badge bg-red"><?php echo $dailyprobs['dp_count']; ?></span></td>
</tr>
<?php endforeach; ?>
<tr><td><?php } else { echo 'No Issues!'; } ?></td></tr>
</table>
  1. $dpc->client 结果一些行,每行都有不同的计数(通过模型中的查询过滤)
  2. $dailyprobs['dp_count'] 当前显示全部结果,而我需要显示按客户分组的总计数

Current Result

如果解释令人困惑,我们深表歉意。我刚刚添加了 View 的图像。如图所示,美标/高仪和 App Sinarmas 的总数量各为 2 = 4,而实际总行数为每列 1(客户)= 2。对不起我的英语。

最佳答案

它只是通过更改模型中的查询来解决:

function get_dailyprob()
{
$date = date('d-m-Y');
$query = $this->db->select('*, COUNT(*) as cnt')->like('created_at', $date)->group_by('client')->get('histprob');
return $query->result();
}

然后在View中使用foreach来获取Count和Rows结果。

关于php - 如何查询多个变量以在 Codeigniter 的 View 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54481565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com