amit
amit

Reputation: 10261

PHP simple poll query

I am starting to learn the ins and outs of PHP and have hit a roadblock. I am making a very simple poll application. Instead of vote-ins, this application would vote-out. What I mean is, the option with the maximum number of votes gets voted-out/eliminated from the poll.

I will create a timer for the vote counts, say, 1 day. Now I am not expecting anyone to draw out a tutorial for this (pointers may be helpful though), but request you all to address a small query:

These might seem like beginner questions. Well, actually they are coming from a beginner.

Upvotes: 0

Views: 784

Answers (2)

eflorico
eflorico

Reputation: 3629

  1. You can use a cron job for that purpose. But as your query doesn't take long, you could also do the check everytime someone requests the poll website. You'll have to save the time when the poll was last updated in the database. To make it perfect, also think of the case that noone visits the website for more than 24 hours: Then you have to eliminate two options.

  2. Usually, you do these by setting a cookie and, if you want, storing the IP address for some time (more than 24 hours doesn't make sense, as many ISPs change IPs after 24 hours). I don't know about the Facebook API, maybe you can just get a user id from there. That would of course be easier and safer.

Upvotes: 0

Galen
Galen

Reputation: 30170

  1. Add a poll_started (datetime) field in your table. Every time a vote is added check if the poll is over 24 hours old. If so delete the top voted option and change the poll_started to the current datetime.

  2. <input type="radio" value="1"><img src="asdfasdf"/> As long as you separate the images well this way will work fine.

  3. not sure

Upvotes: 2

Related Questions