用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2387|回复: 1
收起左侧

[已解决] 怎样将select_avg()语句的查询结果转换成字符串的?

[复制链接]
发表于 2013-4-5 20:44:50 | 显示全部楼层 |阅读模式
本帖最后由 Mapleleaf 于 2013-4-5 20:57 编辑

我想通过select_avg()函数,显示平均值,但是总出错,谢谢了!
代码如下:
public function avg_valuation($share_id){
        $this->db->where('share_id =', $share_id);
        $this->db->select_avg('valuation');
        return $this->db->get('tupu_comment');
}
……
$avg_valuation = $this->comment_model->avg_valuation($share_id);
echo $avg_valuation ;
……
错误结果提示:
A PHP Error was encounteredSeverity: 4096
Message:  Object of class CI_DB_mysql_driver could not be converted to string
Filename: controllers/share.php
Line Number: 110




发表于 2013-4-8 13:11:27 | 显示全部楼层
$this->db->get('tupu_comment'); 这个返回的是一个对象,看文档 http://codeigniter.org.cn/user_guide/database/results.html 即可解决。

本版积分规则