Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving logic problems with a voting system
    primarykey
    data
    text
    <p>i am looking for help on an up down voting system.</p> <p>at the moment i have a voting table that references the user that voted , the user who was voted for and the piece of information(a parking spot) that was voted for</p> <pre><code>CREATE TABLE parking_spots_votes( vote_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, parking_spot_id INTEGER DEFAULT NULL, key parking_spot_id_fk (parking_spot_id), FOREIGN KEY (parking_spot_id) REFERENCES parking_spots(id), uploaded_by_user_id INTEGER DEFAULT NULL, key user_id_fk (uploaded_by_user_id), FOREIGN KEY (uploaded_by_user_id) REFERENCES parking_angel_users(id), vote_casted_user_id INTEGER DEFAULT NULL, key vote_cast_user_id_fk (vote_casted_user_id), FOREIGN KEY (vote_casted_user_id) REFERENCES parking_angel_users(id), vote_type INTEGER NOT NULL ) </code></pre> <p>vote type can be 0 for no vote, 1 for up vote, 2 for downvote</p> <p>now i am having a little logical trouble. </p> <p>for example</p> <ol> <li>what if the user has already voted on a parking_spot</li> <li><p>How do i check if a user has already voted and if he has not then insert but if he has then do not a return voted already.</p></li> <li><p>How do i update a user(uploaded_by_user_id) score. plus one for an up vote and minus one for a down vote. </p></li> </ol> <p>so the general flow would be ,</p> <p>A user presses up vote, the server checks if has been voted for already, if so then you cant vote again. if not then the vote_casted_user_id = current user , parking_spot_id = current info , uploaded_by_user_id = the person who uploaded the info , then the uploaded_by_user score would update depending on the vote type.</p> <p>I am using java servlet with a JDBC connection to a MYSQL database. </p> <p>Any ideas for me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload