Storing “votes” in a database

后端 未结 5 386
既然无缘
既然无缘 2021-02-02 16:44

I\'m writing what will be an intranet application, and one of its features is roughly analogous to content voting - not unlike what SO, Amazon, and many other sites do.

5条回答
  •  执念已碎
    2021-02-02 17:30

    You will probably also want the ID of the author of the content in the table, for easier detection of voting abuse. (Yes, this is presumably redundant information. An alternative is regularly building a summary table to see who is voting on whom.)

    For what it's worth, the perlmonks vote table looks like this:

     `vote_id` int(11) NOT NULL default '0',
     `voter_user` int(11) NOT NULL default '0',
     `voted_user` int(11) default NULL,
     `weight` int(11) NOT NULL default '0',
     `votetime` datetime NOT NULL default '0000-00-00 00:00:00',
     `ip` varchar(16) default NULL,
     PRIMARY KEY  (`vote_id`,`voter_user`),
     KEY `voter_user_idx` (`voter_user`,`votetime`),
     KEY `voted_user_idx` (`voted_user`,`votetime`)
    

    (vote_id is the content id, ip is an IP address.)

提交回复
热议问题