php poll program using mysql
I'm working on a poll program and am wondering, so far all of the sample I've seen makes use of insert then counting the total votes for each answers. I find it redunda开发者_JAVA技巧nt to have a table with a field of answers and a lot of yes, no and maybe
So I am thinking, is it efficient for me to use update instead of insert, for example, if a user vote yes, the yes field will increment? Will it introduce problems with accuracy if users simultaneously vote?
You should have a answer table, after you will have a relationship with user and answer. You could get stats in adding some information (datetime, etc..)
I find it redundant to have a table with a field of answers and a lot of yes, no and maybe
you can add some useful info too, i.e. time of the vote, ip address, cookie and such
Will it introduce problems
No
Your database uses transactions, the update will be atomic. There's no problem with accuracy.
UPDATE MyTable SET MyColumn=MyColumn+1 WHERE MyVoteID=123
精彩评论