简体   繁体   English

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

[英]PHP/MySQL: In a Voting System, how can I keep a user from seeing a profile he has already voted on?

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).我有一个用户表(称为“用户”),每个用户都有一个唯一的用户 ID(列“userID”),我有另一个表(称为“投票”),每个用户给另一个用户的每个投票(使用他们各自的用户 ID 的列“fromUser”、“toUser”、“vote”),所以如果我想向用户显示一个新的随机配置文件进行投票,那么排除当前用户已经投票的任何用户的最佳方法是什么on(换句话说,排除任何“userID”,其中“userID”是“toUser”,“fromUser”是当前用户的 userID)。

Thanks!谢谢!

SELECT userID FROM users
WHERE userID NOT IN (SELECT toUser FROM votes WHERE fromUser = 'theUserIdThatIsVotingNow')
ORDER BY RAND() LIMIT 1

This should do the trick.这应该可以解决问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM