Select每天每笔交易的总和和次数并显示

Select sum and count of every transaction per day and display it

我在做一个监控系统。我的目标是显示我每天的交易总额和数量。我提供了目标的屏幕截图。任何帮助将不胜感激。

查看

<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>

控制器

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);
    }

型号:

//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

模型函数

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();
}

控制器功能:处理数据库响应

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>";
    }
}

查询的 select 部分应处理计数和总和。

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();
}