Corbee
Corbee

Reputation: 1019

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 redundant 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?

Upvotes: 1

Views: 137

Answers (3)

mathieug
mathieug

Reputation: 911

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..)

Upvotes: 2

Brian Roach
Brian Roach

Reputation: 76918

Your database uses transactions, the update will be atomic. There's no problem with accuracy.

UPDATE MyTable SET MyColumn=MyColumn+1 WHERE MyVoteID=123

Upvotes: 0

Your Common Sense
Your Common Sense

Reputation: 157989

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

Upvotes: 1

Related Questions