tags:

views:

51

answers:

2

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:

  • Is it possible to make an automated system, such that, after 24 hours, the most voted-for option gets deleted and the rest remains?
  • Is it possible to use images (possibly JavaScript) for the options. I know it could be done, but some Internet link or example code would be highly appreciated.
  • If I connect this application to Facebook, how do I make sure a user does not vote twice.

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

+2  A: 
  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

Galen
I'd suggest putting the <img> inside a <label> that's connected to the <input> tag.
Jon Benedicto
if i add an img tag inside a radio type input would the radio button still be visible?
amit
A: 
  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.

eWolf