我有 2 个表要比较并找到用户名未关注的用户,然后显示未关注的人的用户名。
Edit:
Table 1: users
username
Table 2: follow
username (the name of the user)
followname (the name of the person the user follows)
In Table 2 username and followname are never null. When a user follows another user then it is put into the list like so:
Username Followname
derekshull dvdowns
derekshull testuser
dvdowns testuser
testuser 1511project
derekshull newuser
在我的脑海中,我看到表 1 获取了所有用户名的列表(列名是表 1 中的“用户名”),然后获取了用户 ($username) 未关注的所有用户名的列表(列名是“followname”来自表 2)。
如何让它比较两个列表而不显示用户已经关注的用户名?
这就是我现在所拥有的。出于某种原因,它正在显示我关注和不关注的用户。
$alluserslookup = mysql_query("SELECT * FROM users WHERE username!='$username'");
$thefollowerslookup = mysql_query("SELECT * FROM follow WHERE username='$username'");
while ($followersrow = mysql_fetch_assoc($thefollowerslookup)) {
$afollower = $followersrow['followname'];
while ($allusersrow = mysql_fetch_assoc($alluserslookup)) {
$allusers = $allusersrow['username'];
if ($afollower != $allusers) {
echo "<a href='viewprofile.php?viewusername=$allusers'>$allusers</a><br>";
}
}
}