Welcome Guest, Not a member yet? Register   Sign In
What should my type be for votes in db
#2

(This post was last modified: 01-16-2017, 02:12 AM by Diederik.)

A tinyint datatype can only store 1 byte of data, storing a max value of just 255. So you cant store a number higher that 255. I guess thats not desired for a voting system to have such a limitation.

http://dev.mysql.com/doc/refman/5.7/en/i...types.html

I would store all votes as unique entries in a different table with more data then you really need but can prove valuable when your voting system gets hijacks or something. Atleast then you have the ability to remove some less desired votes after you have investigated an issue. (for example, when you get 10.000 of votes in an hour originating from some country far far away)

votes:
id, ip, timestamp, useragent, referer, votes_for, etc

Then when you want to display the total number of for for just let the database handle that for you.
Code:
SELECT count(votes_for) as total_votes FROM votes WHERE votes_for='xxx'
Reply


Messages In This Thread
RE: What should my type be for votes in db - by Diederik - 01-16-2017, 02:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB