Youtube-like like/dislike rating system code wante

2019-09-02 04:52发布

I am trying to make a rating system, very similar to Youtube's thumbs Up/Down. Actually, I was hoping to achieve exactly the same. But from what I gather from here: http://code.google.com/apis/youtube/2.0/developers_guide_protocol.html#Ratings

Youtube uses an API to take care of all the Ratings. So I am looking for info and help on how can I set up the same system YT has. I basically want to have a Like/Dislike function for every page, which is liked to a specific object on that page - just like the like/dislike is linked to a video on every page. Preferrably also one for comments. All help is very very welcomed. From source-codes for already done systems (I searched around google quite a bit, but never found a similar open-source rating system) to help and info on how I can set up the API-powered rating system.

2条回答
劫难
2楼-- · 2019-09-02 05:28

For the database part, if you need to know which users liked which videos, then use two tables, one for likes and one for dislikes:

TABLE likes {
   user_id
   video_id
}

TABLE dislikes {
  user_id
  video_id
}

Both tables associate a user with a video.

查看更多
等我变得足够好
3楼-- · 2019-09-02 05:48

I would suggest having a database with all videos and comments, that has a field for likes and dislikes. you can then update the database with javascript click events to perform ajax calls to increment the count. you could use jquery and the code would be as simple as:

$('#up_button').click(function(){
    var id = $(this).attr('thisid');
    $.ajax({ type: 'POST',
        url: 'AJAX/Handler/Upvote',
        data: { video_id: id },
        dataType: 'html',
        success: function (data) { alert('success'); },
        error: function (xhr, err) { alert('Error:\n\nreadyState: " + xhr.readyState + "\nstatus: " + xhr.status + "\nresponseText: " + xhr.responseText); }
    });
});
查看更多
登录 后发表回答