1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Voting Script Help

Discussion in 'Web Design & Development' started by covert215, Jul 29, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. covert215

    covert215 Banned Thread Starter

    Joined:
    Apr 22, 2006
    Messages:
    2,595
    I am in the process of programming a joke site. I currently have implemented an image and joke of the day script. I also programmed a random image viewer. There is a joke database set up that allows a user to submit jokes, along with a title and category. Once a joke has been submitted, it can be rated. If after 10 votes that average is below 2, the joke is removed from the database. I want to be able to limit a user to 1 vote per joke. How can this be accomplished?
     
  2. bassetman

    bassetman Moderator (deceased) - Gone but never forgotten

    Joined:
    Jun 7, 2001
    Messages:
    47,973
    Ensabled cookies
     
  3. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    You can save a cookie like basset said, and also store their IP address along with a record of which jokes they've voted on (otherwise they could clear their cookies and vote repeatedly.)
     
  4. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    You could also have users register with their email address and limit them to 1 vote per user.
     
  5. redivivus

    redivivus

    Joined:
    Mar 30, 2006
    Messages:
    1,458
    Or you can store some form of encrypted string in their cookies and only let them vote after a couple days on the site or something. ;)

    It wouldnt be foolproof because you would need some good obfuscated js.

    I suggest going with 1 vote per IP and/or email. :eek:
     
  6. covert215

    covert215 Banned Thread Starter

    Joined:
    Apr 22, 2006
    Messages:
    2,595
    I know how to capture the ip, but i don't know how to structure my database so that it checks which items have already been voted on
     
  7. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    SELECT * FROM votes WHERE ip = their_ip AND poll = poll_id
    Query that, and if mysql_num_results() is greater than 0, they've already voted on that poll.
     
  8. covert215

    covert215 Banned Thread Starter

    Joined:
    Apr 22, 2006
    Messages:
    2,595
    The problem is, the number of jokes in the database is dynamic. When there are more than 20 jokes or so, the code becomes very inefficient.

    I think I am just going to log each IP and allow it 5 votes per day.

    How do I make it so that the server recognizes that it is a new day?
     
  9. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    MySQL doesn't have any problem with 20 rows in a database. That query will take well under a second to run.
     
  10. covert215

    covert215 Banned Thread Starter

    Joined:
    Apr 22, 2006
    Messages:
    2,595
    20 was probably a bad example...more like 200 or so. Anyways, how do I make it so that the server recognizes that it is a new day?
     
  11. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    This forum with 200,000+ members runs on MySQL, it can really handle your 200 jokes with no problem.

    You can use time() to get a timestamp or date() to get the date.
     
  12. covert215

    covert215 Banned Thread Starter

    Joined:
    Apr 22, 2006
    Messages:
    2,595
    So, I set up a 3 column table. IP, Votes, Day. Every time a new user votes I create a new row, logging the IP and day. I will test if each vote is made on the same day. If it recognizes a new day, it will reset the votes column. It sounds good in theory...I just have to program it.
     
  13. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    Just make the table IP and Poll ID, then you can insert the IP along with an ID number for each different poll. Then when someone votes you can check if they've already voted on that specific poll.
     
  14. covert215

    covert215 Banned Thread Starter

    Joined:
    Apr 22, 2006
    Messages:
    2,595
    Can I dynamically add a new column whenever a new poll is added?

    btw, it seems like just me and you are conversing in 2 threads right now
     
  15. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    Seems so...
    You don't need to add a new column, just give each poll a unique ID number. Every time someone votes, store their IP address along with the ID number of the poll they voted in.
    Then you can do SELECT * FROM votes WHERE IP=their_ip and POLL=poll_id
    If there's a matching column, then they've already voted.
     
  16. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/487688

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice