我在控制器上有此查询:
$this->db->select('t1.act_id, t2.login, t1.cust_name, t1.act_type, t1.act_detail, t1.date_added, t1.date_modified, t1.act_notes, '
. 't3.category, t1.total_time, sum(t1.total_time) as total')
->from('activity as t1')
->join('user as t2', 't1.user_id = t2.user_id', 'LEFT')
->join('customer as t3', 't1.cust_name = t3.cust_name', 'LEFT')
->where('t2.login', $user)
->where('MONTH(t1.date_added)', $month)
->order_by('t1.date_added', "desc");
$query = $this->db->get();
$result = $query->result_array();
$data = array('title' =>'Sales Report'." - ".$user,
'user' => $result);
$this->load->view('admin/report/vw_report_excel', $data);
我要发布此SUM值
sum(t1.total_time) as total
但我不断出错,说“试图获取非对象的属性”
这是我在视图(vw_report_excel)上的调用方式:
<?php echo ($user->total); ?>
调用或声明的正确方法是什么?
问候
这是我的看法,我希望将SUM从表/循环中排除.
<?php echo $xuser['act_id']; ?><?php echo $xuser['login']; ?><?php echo $xuser['cust_name']; ?><?php echo $xuser['act_type']; ?><?php echo $xuser['act_detail']; ?><?php echo $xuser['date_added']; ?><?php echo $xuser['date_modified']; ?><?php echo $xuser['act_notes']; ?><?php echo $xuser['category']; ?><?php echo $xuser['total_time']; ?><?php echo count($user); ?><?php echo ($user->total); ?>解决方法:
result_array()
This method returns the query result as a pure array, or an empty
array when no result is produced. Typically you’ll use this in a
foreach loop, like this:
所以使用foreach()
foreach($user as $usr){
echo $usr['total'];
}
或使用:- (基于您对问题的代码修改)
标签:codeigniter,php
来源: https://codeday.me/bug/20191025/1927301.html