PDA

Click to See Complete Forum and Search --> : vote only one time per link


yair24
Feb 21st, 2004, 11:21 AM
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

kows
Feb 21st, 2004, 09:33 PM
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/php/vote/?file=vote.php
rate.php
http://david.gamersepitome.net/files/php/vote/?file=rate.php
mysql_dump.txt
http://david.gamersepitome.net/files/php/vote/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.

yair24
Feb 22nd, 2004, 03:44 AM
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

CornedBee
Feb 22nd, 2004, 08:05 AM
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.

yair24
Feb 22nd, 2004, 10:10 AM
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