【求助】Cannot use a scalar value as an array 错误
本帖最后由 北望天堂 于 2012-11-10 15:36 编辑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;
}
}
$result[$key]['user']=array('uid' => "00", 'username' => '佚名', 'nikename' => '佚名');
//上面这行提示错误 Message:Cannot use a scalar value as an array $result的数据类型问题。而且,你在foreach中使用了$result AS $key => $value,下面竟然还在使用$result变量作赋值,亲,这不科学。 应该是等号两边数据类型不同
页:
[1]