Jump to content

How to check if one user did something ?


abyssal

Recommended Posts

Hey guys. I have site with questions and answers. Users can also vote on the answer they like at a question. The thing is I want a user to be able to vote only one answer from each question. If he likes an answer, he can vote +1 on that answer, but then he won't be able to vote for any other answer in that certain question.

 

The problem here is that I don't even know how to do it  code it.

 

I also retain the questions and answers into 2 separate SQL tables, answer and questions.

 

Any ideas?

Link to comment
Share on other sites

How do people get to vote on the questions? do they have to be registered and logged in? if so, you can store whatever questions they have already voted for in a database (i.e database with: userid, questionid).

then, whenever a user tries to vote on a question (or before you display the questions to the user, whichever way you prefer) you check that database for matches. if there is a match, it means the user has already voted.

 

... and, of course, when a user votes, you insert userID + questionID in the database. You can also store the users answer, date, time, etc... May be useful later.

 

Hope this helps

Link to comment
Share on other sites

Since you do not have a database for tracking the users votes yet, and seeing an html page does not give me access to your php code, that really does not help me understand better.

 

Create a table in the database like I said, with whatever extra info you might want to store, I suggest:

table: userVotes

id, questionID, userID, vote, date, time, ip

 

and then do what I suggested: everytime a user votes on a question, insert a line in that database (the vote filed is to store 1 or -1 depending on the vote)

 

then, when you load the page, you can count all the votes for each question and also track if a certain user has already voted.

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.