|
本帖最后由 北望天堂 于 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;
}
}
复制代码
|
|