Results 1 to 5 of 5

Thread: vote only one time per link

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    74

    vote only one time per link

    hello,
    I need your advice:

    I am building a website that contains alot of links in a database.
    the website shows the links and allow the users to vote for each link.

    that means the links are set up in a table and each links has two icons:

    one for "good" one for "bad" if the user clicks on the "good" it will count his vote and increment it by 1. and the same goes for the "bad" too (if the user click on the "bad" it wil increment his vote by 1)
    and every link shows how many users voted "good" and how many voted "bad".

    my question is this:

    I only allow to registered users to vote, and I would like to allow them voting only once per link.

    what is the best way of doing so?
    I thouhjt of cookies but I dont think I can keep so much information on a cookie... no?

    (I mean after all I have many links in my database and a cookie is limited in its size no?)

    so I thought maybe use a table in the database to keep the voters for each link?

    what do you think?

    Yair
    -------------------------------------
    http://www.ybweb.com

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    If you're using a MySQL database to store the information, and you are only allowing registered users to vote, then make a new field in your table that has a named like 'already_voted' as a text type which will store all of the users' names who have already voted.

    Do you wish to have code provided for being able to increment the vote counts or are you able to do that yourself? I'll make some sort of a sample..

    Well, I worked on this for a while, and came up with this.. it's probably real ugly, but it works for what I think you want to do, and if it doesn't help you/you want to do it yourself, hopefully it will at least point you in the right direction.

    Here's the source:
    vote.php
    http://david.gamersepitome.net/files...?file=vote.php
    rate.php
    http://david.gamersepitome.net/files...?file=rate.php
    mysql_dump.txt
    http://david.gamersepitome.net/files...mysql_dump.txt

    Here's a working demo of it:
    http://david.gamersepitome.net/files/php/vote/vote.php

    Use the username "test" and the password "test" to test it out.. I've also made the test accounts "test2" and "test3" with their corresponding passwords for demo purposes.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    74

    thanks for your answer...

    you realy make a big effort here...

    but unfortunately I cannot understand this code as it is too complicated for me to understand...

    I wil however ask another question here:

    I have this idea:
    I belive that cookies is a bad way to do so because I can have unlimited links in my database.
    therefor I think of creating another table with two columns:

    USERNAME LINKNUMBER

    everytime someone makes a vote I will put his username and the linknumber that hevoted for.

    and before voting I will check if there is an existing record that contains the username and the link.

    if there is a recordset like this then it means that this user already voted for the specific link.
    if there is no record like this then it means the user didnt voted yet and I wil allow him to vote and add his usename and linknumber for the next time he will try to vote for the same link.

    my question is this:

    this kind of table might fill very fast and might contain many many records, suppose this table will contain milions of records will it make the vote proccess go slower?

    Yair
    -------------------------------------
    http://www.ybweb.com

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    That's what databases are designed for, to hold large tables with many many entries. Make sure you have an index on both columns. This will require more space, but will make lookups faster.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    74

    thank you for that answer

    I have been told twice today to make an index to the database.
    can you tell me plese how can I make the index?
    and how does it functioning?

    Yair
    -------------------------------------
    http://www.ybweb.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width