php 数组取数据,PHP:从数组获取数据

我在控制器上有此查询:

$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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值