Home › Forums › Back End › User voting system problem › Reply To: User voting system problem
March 20, 2014 at 12:20 pm
#166401
Participant
I’m still not really sure how I test for users with less than 10 votes or no votes at all though?
I think @jurotek pointed this out earlier, but you’d simply use left join
instead of a regular join
. This way, you get all results from the user table that don’t have a matching vote.
I can add a vote once which works fine and if I try to vote again I get a SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘2’ for key ‘PRIMARY’error.
Which points out how you can manage errors: if you get an SQL error, check if the error code was 23000
. If so, you can display a message to the user along the lines of “You’ve already voted.”