1

我有两张桌子:

sk_accounts      //details of user
  • acnt_user_id
  • acnt_fname //名字
  • acnt_lname
  • acnt_profile_picture
  • acnt_member_class
  • 很快........

     sk_following   //table containing details of users who are following others
    
  • ID

  • flwing_follower_id //被其他关注者关注的用户的id
  • flwing_following_user_id
  • 以下日期

    我想根据以下 Mysql 代码显示关注者的详细信息。不幸的是,即使有 3 行,它也会返回零行。我的查询是这样的:

    $query_following = "SELECT sk_following.flwing_following_user_id, 
    sk_accounts.acnt_fname,
    sk_accounts.acnt_lname,
    sk_accounts.acnt_member_class,
    sk_accounts.acnt_profile_picture
    FROM sk_following 
    INNER JOIN sk_accounts 
    WHERE sk_following.flwing_follower_id='$id' AND        sk_accounts.acnt_user_id=sk_following.flwing_following_user_id AND CONCAT(sk_accounts.acnt_fname,' ',sk_accounts.acnt_lname)='$name'";
    $result_following = mysql_query($query_following);
    $count_following = mysql_num_rows($result_following);
    echo $count_following;
    

注意:$id 和 $name 包含值请帮助我。在此先感谢。

4

2 回答 2

2

试试这个,

"SELECT sk_following.flwing_following_user_id,
sk_accounts.acnt_fname,
sk_accounts.acnt_lname,
sk_accounts.acnt_member_class,
sk_accounts.acnt_profile_picture 
FROM sk_following
LEFT JOIN sk_accounts ON sk_accounts.acnt_user_id=sk_following.flwing_following_user_id
WHERE sk_following.flwing_follower_id='$id'
AND CONCAT(sk_accounts.acnt_fname,' ',sk_accounts.acnt_lname)='$name'";

这可以帮助你。

于 2013-01-31T06:53:19.890 回答
1

如果没有看到示例数据和所需的输出,很难完全理解,但是您的 JOIN 是否应该在 flwing_follower_id 而不是 flwing_following_user_id 上?

SELECT sk_following.flwing_following_user_id,
    sk_accounts.acnt_fname,
    sk_accounts.acnt_lname,
    sk_accounts.acnt_member_class,
    sk_accounts.acnt_profile_picture 
FROM sk_following 
    INNER JOIN sk_accounts ON sk_accounts.acnt_user_id=sk_following.flwing_follower_id 
WHERE sk_following.flwing_follower_id='$id' 
    AND CONCAT(sk_accounts.acnt_fname,' ',sk_accounts.acnt_lname)='$name'

祝你好运。

于 2013-01-31T06:44:19.643 回答