PHP/MySQL:在投票系统中,如何阻止用户看到他已经投票过的个人资料?

发布于 2024-11-28 23:12:25 字数 304 浏览 0 评论 0原文

一般来说,如何阻止用户看到他已经投票过的个人资料,以免他对其投票两次?

我有一个用户表(称为“用户”),每个用户都有一个唯一的用户 ID(列为“userID”),我还有另一个表(称为“投票”),用于每个用户向另一个用户提供的每次投票(使用他们各自的投票)用户 ID 的列为“fromUser”、“toUser”、“vote”),因此,如果我想向用户显示一个新的随机配置文件进行投票,那么排除当前用户已投票的任何用户的最佳方法是什么上(换句话说,排除任何“userID”,其中“userID”是“toUser”,“fromUser”是当前用户的用户ID)。

谢谢!

Generally speaking, how can I keep a user from seeing a profile he has already voted on so that he does not vote on it twice?

I have a table (called "Users") of users each with a unique user ID (with column "userID"), I have another table (called "Votes") for each vote given by each user to another user (using their respective user ID's with columns "fromUser", "toUser", "vote"), so if I want to show a user a new random profile to vote on, then what is the BEST way to exclude any users where the current User has already voted on (in other words, exclude any "userID" where the "userID" is the "toUser" and where the "fromUser" is the current user's userID).

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝對不後悔。 2024-12-05 23:12:25
SELECT userID FROM users
WHERE userID NOT IN (SELECT toUser FROM votes WHERE fromUser = 'theUserIdThatIsVotingNow')
ORDER BY RAND() LIMIT 1
SELECT userID FROM users
WHERE userID NOT IN (SELECT toUser FROM votes WHERE fromUser = 'theUserIdThatIsVotingNow')
ORDER BY RAND() LIMIT 1
豆芽 2024-12-05 23:12:25

这应该可以解决问题。

SELECT * 
FROM Users 
WHERE userID NOT IN (SELECT toUser FROM Votes WHERE fromUser = '$current_user_userID');

This should do the trick.

SELECT * 
FROM Users 
WHERE userID NOT IN (SELECT toUser FROM Votes WHERE fromUser = '$current_user_userID');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文