开发者

Voting system adds and subtracts 1-5 each time

开发者 https://www.devze.com 2023-01-29 23:04 出处:网络
So, I implemented a voting system http://ad1987.blogspot.com/2009/02/reddit-style-voting-with-php-mysql-and.html

So, I implemented a voting system

http://ad1987.blogspot.com/2009/02/reddit-style-voting-with-php-mysql-and.html

on my website. It works perfectly, except for the fact that each time you vote up or vote down it can add anywhere from 1-5 or so votes. The source code is pretty much the same to that on that website, so if you'd like to see it, please check it out there. For a live example:

ht开发者_开发知识库tp://www.campusbasement.com/cornell/entertainment/articles/927/electro-is-taking-over-the-world

Thanks

votes.php: http://pastie.org/1369778


I had a somewhat similar problem. Chrome for some still unknown reason downloaded each page twice, so the views counter was getting +2 each time.

I suppose you have a user table with user_id, and an article table with article_id. So you can implement the check connecting this two tables with many-to-many relation. You should create an intermediate table with fields post_id - the post being voted for, user_id and optionally a value field (if the user decides to change his vote). The first two fields might be a composite primary key.

So when user votes, you search for the row with the same post and user ids. If there are non - you add it.


The problem is that there is no check wether someone has already voted. So you need to either set a cookie (which can fail quite often) or check IP and browser for example... The best thing would be to check the User ID (if it is only possible to vote when logged in).

// EDIT:
I just read in the comments of your first post that the problem is the vote count when voting just once...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号