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

【求助】Cannot use a scalar value as an array 错误

[复制链接]
发表于 2012-11-10 15:33:37 | 显示全部楼层 |阅读模式
本帖最后由 北望天堂 于 2012-11-10 15:36 编辑
PHP复制代码
 
    public function getuserfavorite($uid = false) {
        $result = array();
        if ($uid) {
            $result['userbookcount'] = $this -> db -> get_where('book_favorite', array('uid' => (int)$uid)) -> num_rows();
            //用户收藏个数
            $query = $this -> db -> order_by('ctime', 'desc') -> get_where('book_favorite', array('uid' => (int)$uid));
            //用户收藏表
            foreach ($query->result_array() as $key => $value) {
                $temp = $this -> db -> select('book_id,book_name,book_author,book_time,anchor,anchor_other,book_img,category_id') -> get_where('book', array('book_id' => $value['bid'])) -> row_array();
                $temp['bookscount'] = $this -> db -> get_where('book_article', array('bid' => $temp['book_id'])) -> num_rows();
                $temp['userbookscount'] = $this -> db -> get_where('book_favorite', array('uid' => (int)$uid, 'bid' => $temp['book_id'])) -> num_rows();
                $result[] = $temp + array('ctime' => $value['ctime']);
            }
            foreach ($result as $key => $val) {
                if ($val['anchor']) {
                    $result[$key]['user'] = $this -> db -> select("uid,username,nikename") -> get_where('user', array('username' => $val['anchor'])) -> row_array();
                    if (empty($result[$key]['user'])) {
                         $result[$key]['user']=array('uid' => "00", 'username' => '佚名', 'nikename' => '佚名');
                     }
                } else {
                        $result[$key]['user']=array('uid' => "00", 'username' => '佚名', 'nikename' => '佚名');
//上面这行提示错误   Message:  Cannot use a scalar value as an array
                }
            }
            return $result;
        } else {
            return null;
        }
    }
 
复制代码

 楼主| 发表于 2012-11-10 15:36:16 | 显示全部楼层
$result[$key]['user']=array('uid' => "00", 'username' => '佚名', 'nikename' => '佚名');
//上面这行提示错误   Message:  Cannot use a scalar value as an array
发表于 2012-11-10 21:29:38 | 显示全部楼层
$result的数据类型问题。而且,你在foreach中使用了$result AS $key => $value,下面竟然还在使用$result变量作赋值,亲,这不科学。
发表于 2012-11-16 13:07:43 | 显示全部楼层
应该是等号两边数据类型不同

本版积分规则