[英]Select sum and count of every transaction per day and display it
I am making a monitoring system.我正在制作一个监控系统。 My target is to show the sum and count of my transactions per day.
我的目标是显示我每天交易的总和和计数。 I have provided a screenshot of my target.
我提供了我的目标的屏幕截图。 Any help will be appreciated.
任何帮助将不胜感激。
View看法
<tr>
<th scope="col"><i class="far fa-calendar-alt mr-2"></i>Date</th>
<th scope="col"><i class="fas fa-user-tie mr-2"></i>Total Transaction</th>
<th scope="col"><i class="fas fa-user-tie mr-2"></i>Amount</th>
<th scope="col"><i class="fas fa-user-tie mr-2"></i>Action</th>
</tr>
Controller控制器
public function testing()
{
$list = $this->repo->function_etc();
$data = array();
$no = $_POST['start'];
foreach ($list as $person) {
$no++;
$row = array();
$row[] = $person->dateUp;
$row[] = number_format($person->amount);
$row[] = number_format($person->count);
$row[] ='<a class="btn btn-sm buttoon" href="https://sample.com/etcetc='.$person->dateUp.'" ><i class="glyphicon glyphicon-pencil"></i>View</a>';
$data[] = $row;
}
$output = array(
"data" => $data,
);
echo json_encode($output);
}
Model :型号:
//maybe i'm missing something here?
private function function_etc()
{
$this->db->select('*');
$this->db->from($this->tableDashboard);
$this->db->where('transReference !=', '');
$this->db->where('trans_siteName','https://somewhere.com/');
$this->db->select_sum('tbl_transaction.amount');
$this->db->group_by('tbl_transaction.dateUp');
$query = $this->db->get();
return $query->result();
}
SELECT Date, COUNT(ID) AS 'TranCount', SUM(amount)
FROM table
WHERE DATE(date )= DATE(now())
GROUP BY date
MODEL FUNCTION模型功能
function tested() {
$this->db->select('Date,sum(Amount) as Total');
$this->db->from('tbl_transaction');
//$this->db->where('transReference !=', '');
//$this->db->where('trans_siteName','https://somewhere.com/');
$this->db->group_by('Date');
$query = $this->db->get();
return $query->result_array();
}
CONTROLLER FUNCTION: To process the database response CONTROLLER FUNCTION:处理数据库响应
function tested() {
$this->load->model('repo');
$result = $this->repo->tested();
foreach ($result as $k => $v) {
$Date = $v['Date'];
$Total = $v['Total'];
echo $Date. $Total . "<br>";
}
}
Your select section of The query should handle the count and sum.您的查询的选择部分应该处理计数和总和。
private function function_etc()
{
$this->db->select('*, sum(amount) amt, count(ID) num');
$this->db->from($this->tableDashboard);
$this->db->where('transReference !=', '');
$this->db->where('trans_siteName','https://somewhere.com/');
$this->db->select_sum('tbl_transaction.amount');
$this->db->group_by('tbl_transaction.date');
$query = $this->db->get();
return $query->result();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.