我有两张桌子:
sk_accounts //details of user
等........
sk_following //table containing details of users who are following others
ID
following_date
我想根据以下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包含值 请帮助我。谢谢。
答案 0 :(得分: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'";
这可能对你有所帮助。
答案 1 :(得分: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'
祝你好运。