Search code examples
phpjavascripthtmlmysqlranking

turning images into rating system


Here's one that someone with some good web dev experience can really sink their teeth into:

I have a series of 4 images:
1. thumbs-up.jpeg
2. thumbs-up-unclicked.jpeg
3. thumbs-down.jpeg
4. thumbs-down-unclicked.jpeg

Here is the webpage that I have right now, of my four images, which change on mouseover: http://stateofdebate.com/test.html

What I'd like to do is be able to rate each debate topic (http://stateofdebate.com/debatelist.php), and also to rank arguments...to view arguments, sign up, enter a username and password, and login. Then you can click on any of the debates and see an argument.

There are several tasks that I don't know how to accomplish:
1. how to link the images with the mySQL database (do i turn them into some kind of object..?)
2. how to relate the thumbs up/down with each item (i.e. how to make a thumbs up/down ranking for each item)
3. how to get the debate topics to shift up and down based on which one has a better ratio of up/down

I know this may seem vague, but if you look at the links, it may clear things up.

Thanks!


Solution

  • Each user should have a record in a users table

    users
    id,...
    

    Each image should have a record in an image table

    images
    id,created_date,file_path,...
    

    Each vote should have a record in a junction table that looks like:

    image_votes
    user_id,image_id,vote_value
    

    where the value is 0 for a down vote, 1 for an upvote, and no record exists for a nonexistent vote

    further, for comments you would have a table that looks like

    image_comments
    id,image_id,user_id,text,created_date
    

    then you could have a simliar voting system for comments