此代码适用于我的追随者系统。我想查询数据库以显示关注我的用户。函数 show_users_following_you(my id) 在第 9 行返回错误。有人可以解释它的来源吗?
此代码适用于我的追随者系统。我想查询数据库以显示关注我的用户。函数 show_users_following_you(my id) 返回错误。有人可以解释它来自哪里吗?
function show_users_following_you($user_id=0){
if ($user_id > 0){
$follow = array();
$fsql = "select follower_id from following where user_id='". $user_id ."'";
$fresult = mysql_query($fsql);
while($f = mysql_fetch_object($fresult)){
array_push($follow, $f->user_id);
}
if (count($follow)){
$id_string = implode(',', $follow);
$extra = " and id in ($id_string)";
}else{
return array();
}
}
$users = array();
$sql = "select id, username from users where status='active' $extra order by username";
$result = mysql_query($sql);
while ($data = mysql_fetch_object($result)){
$users[$data->id] = $data->username;
}
return $users;
}
评论表结构是
两列:
user_id 对应谁被关注, Follower_id 对应谁在做关注。