abyssal Posted June 24, 2011 Share Posted June 24, 2011 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? Quote Link to comment Share on other sites More sharing options...
EdwinPaul Posted June 24, 2011 Share Posted June 24, 2011 I suppose your quiz is in a form. In that case it is simpel: put the answers in a <select .. > <option .. > combination. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 24, 2011 Share Posted June 24, 2011 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 Quote Link to comment Share on other sites More sharing options...
abyssal Posted June 24, 2011 Author Share Posted June 24, 2011 Ok, for a better understanding, go here: http://8503.a.hostable.me/ login with: user: lette password: parola Than go here: http://8503.a.hostable.me/view.php?id=42 Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 24, 2011 Share Posted June 24, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.