Jump to content

[SOLVED] Best Way To Track Forever


jfarthing

Recommended Posts

Let's say I have a website where users post their music and other users rate it.  What would be the most logical way to allow a user to only rate a particular song once FOREVER also storing what they rated that song as?  the songs are stored in one mysql database, and the users in another...I'm probably thinking too hard about this!

Link to comment
Share on other sites

Just have you script to insert a value in a field in your database in the row of the usersname once they have voted. Then before processing a vote; validate the usersname who is voting too see if the database field has a specific value in it. If it does; then don't let them vote again and if it does; let them vote. you could dynamically change the value to be inserted into the db field and to be validated for each poll you have.

Link to comment
Share on other sites

I was thinking about creating a field for the user who is doing the voting within their row, adding a field called votes, and make it a comma delimited list of every song ID they have voted for and then checking if a song ID is within that list....is this logical and/or efficient?

Link to comment
Share on other sites

that could end up being a MASSIVE table.  Could I do as I was saying, but further delimit the array such as

 

10198:5, 10283:2, 1203:4

 

where the first part is the song id, proceeding the colon is the vote value proceeding the comma is the next song/vote combo etc etc...?  If so, how would I retrieve a specific song/vote out of that?

Link to comment
Share on other sites

you probably could do it that way, but an easier way; if your going that route would be to create a field for the vote and a field for the song numbers. you may have to create a complex array and explode each comma if you want to validate if user has voted or not, but then again you might be able to explode each comma in a simple array for each database field (vote and song id) and use a basic if else condition to validate.

Link to comment
Share on other sites

So create a seperate table just for voting and basically have 3 fields, songID, voterID, voteValue.  Then on the voting page, to validate, query that table something like:

$voteQuery = mysql_query("SELECT * FROM votes WHERE voterID = '$usrID' AND songID = '$songID'") or die (mysql_error());

if (mysql_num_rows($voteQuery) > 0) {
  echo "You have already voted for this song!";
} else {
  /***Show Voting***/
}

 

Damn, just thinking though, each user (could be thousands) could vote for 1000's of songs....again a MASSIVE table...will this be a potiential problem??

Link to comment
Share on other sites

you could but then you would have to use a JOIN

 

what I was saying was in the table where you username and password is; create two new fields right beside your username and password (vote, song id/number). then use commas or something to seperate each vote and each song id/number. either way; this is going to take up some database space - the way your wanting to do this.

 

you could always do like I said before, but that would be a good method for maybe only a few votes and maybe only a few songs; not a massive amount of vote and a massive amount of songs.

 

http://www.phpfreaks.com/forums/index.php/topic,170311.msg752487.html#msg752487

Link to comment
Share on other sites

I personally would rather use a database; I really don't like text files for storing data accurately. I have stored data in a text file in the past and some how it got alternated in a way it shouldn't have. I just think database data is allot more secure then text file data, but hey - that's just me. Which ever you think works the best for you or creates less a file size for your server/host; then go for it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.