YouTube Style Rating/Voting System using jQuery, Ajax and PHP. Ever Best Tutorial !

Today I have created Youtube style rating system which is also called thumbs up/down rating. It is 99% identical to original youtube rating system. I have tried my best to give you a stylish and same youtube look rating system. I have implement IP address checks so that a single user can rate once. It looks very awesome please try it and give your feed backs.
Database Structure
CREATE TABLE IF NOT EXISTS `youtube_ip` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userip` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
)
CREATE TABLE IF NOT EXISTS `youtube_rating` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`liked` int(11) NOT NULL,
`dislike` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
INSERT INTO `youtube_rating` (`id`, `liked`, `dislike`) VALUES
(1, 0, 0);
jquery code that is used:
$(document).ready(function() {
$('.like_button').mouseenter(function(e) {
$('.tooltip').show();
$('.ilikethis').fadeIn(200);
}).mouseleave(function(e) {
$('.ilikethis').fadeOut(200);
$('.tooltip').hide();
});
$('.dislike_button').mouseenter(function(e) {
$('.tooltip2').show();
$('.idislikethis').fadeIn(200);
}).mouseleave(function(e) {
$('.tooltip2').hide();
$('.idislikethis').fadeOut(200);
});
$('.totalstatsbutton').livequery("mouseenter", function(e){
$('.greenBar').css("background-color","#AADA37");
$('.redbar').css("background-color","#CF362F");
$('.tooltip3').show();
$('.totalstats').fadeIn(200);
}).livequery("mouseleave", function(e){
$('.tooltip3').hide();
$('.greenBar').css("background-color","#DDDDDD");
$('.redbar').css("background-color","#DDDDDD");
$('.totalstats').fadeOut(200);
});
});
$(document).ready(function(){
//$('#voting_result').fadeOut();
$('button').click(function(){
var a = $(this).attr("id");
$.post("voting.php?value="+a, {
}, function(response){
$('#voting_result').fadeIn();
$('#voting_result').html($(response).fadeIn('slow'));
// now update box bar
$.post("update_box.php", {
}, function(update){
$('#update_count').html(unescape(update));
});
////////////
// now update tooltip count
$.post("update_tooltip.php", {
}, function(updates){
$('.tooltip3').html(unescape(updates));
});
////////////
});
});
});
75 to “YouTube Style Rating/Voting System using jQuery, Ajax and PHP. Ever Best Tutorial !”
Post comment

Categories
- AJAX (28)
- Announcement (3)
- Blogging Tips (1)
- Codeigniter (16)
- CSS (14)
- Facebook (8)
- Freelance Tips (1)
- How-To (2)
- Joomla (1)
- JQuery (51)
- Miscellaneous (3)
- Mootools (1)
- MySQL (3)
- PHP (57)
- SEO (2)
- Technology (6)
- Tutorials (17)
- Twitter (2)
- Web Design (26)
- Web Development (58)
- WordPress (3)
Popular post
- 46 Highly Responsive Admin Templates for Your Websites
- $50 PayPal Cash & 5 Premium PHP Wall Script Prizes #Giveaway
- PHP Wall Script Clone with Real Time Features __ January 2013 Release __
- Things you should know if you are a Blogger
- Top 10 Must Have Qualities of a Freelance Web Developer
- Fundamental Factors for Mobile Compatible eCommerce Hosting
- Facebook Wall Script New Version in September 2012
Recommend

wow! another wow!
I have this problem , pleace if you can give me advice
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\tube\update_box.php on line 5
Warning: Division by zero in C:\xampp\htdocs\tube\update_box.php on line 14
Warning: Division by zero in C:\xampp\htdocs\tube\update_box.php on line 16
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\tube\voting.php on line 19
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\tube\voting.php on line 48
Warning: Division by zero in C:\xampp\htdocs\tube\voting.php on line 57
Warning: Division by zero in C:\xampp\htdocs\tube\voting.php on line 59
Great capturing system here, thanks for taking the time to build this out and share it with so many! The DB that I downloaded wasn’t matching up correctly though. I had to break out the ip to it’s own table, when I imported your sql dumped file it merged the ip into the rating table vs. generating it’s own table.
Below is the final table structure after making the necessary modifications if anyone would like to grab from here:
– phpMyAdmin SQL Dump
– version 3.4.7.1
– http://www.phpmyadmin.net
–
– Host: localhost
– Generation Time: Nov 15, 2011 at 05:01 AM
– Server version: 5.1.59
– PHP Version: 5.2.9
SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;
SET time_zone = “+00:00″;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
–
– Database: `govector_masherpoll`
–
– ——————————————————–
–
– Table structure for table `youtube_ip`
–
DROP TABLE IF EXISTS `youtube_ip`;
CREATE TABLE IF NOT EXISTS `youtube_ip` (
`id` int(100) NOT NULL AUTO_INCREMENT,
`userip` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;
– ——————————————————–
–
– Table structure for table `youtube_rating`
–
DROP TABLE IF EXISTS `youtube_rating`;
CREATE TABLE IF NOT EXISTS `youtube_rating` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`liked` int(11) NOT NULL DEFAULT ’0′,
`dislike` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
–
– Dumping data for table `youtube_rating`
–
INSERT INTO `youtube_rating` (`id`, `liked`, `dislike`) VALUES
(1, 0, 0);
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
You had the echos reversed for the like and dislike as it should be likes, dislikes. Now it works perfectly, thanks again for a great tool you’ve built here!
Welcome Kevin
and thanks for sharing DB It would be help full for the users.
Tommy, you must have empty record which you are diving. Try to inspect it step by step there must be empty data coming through….
any advise on using this for multiple pages.. im having a tough time getting it too work
You can use some sort of flag id with the rating. Such as If you want to add this rating on a video then in table create a new field vid_id which will store that video ID so that you can differentiate which rating is for which video. For pages you can save pageID so that you can get specific pages rating.
Many MANY thanks for this. This is simply a fantastic system. Big thanks to Kevin there for fixing up the SQL. I’ve fiddled around with this for a few days and it is working SWEET!
I’ve been looking everywhere so thank you so much for this! I am new phpmyadmin and such and I think I installed everything right but when I test it out nothing shows. Am I missing something?
The downloaded version has wierd positioning issues in ie 9 with the dislike button hanging below, works greats with every other browser. How to fix this issue?
Man I have same Problem How Can i Fixed ?
Thank You So much bro…. for such a wounderfull article
Thanks to all again
Hi there, I’m working with your code and noticed that you reference “$.post(“rating.php?show=1″,”
In the downloaded RAR, there is no rating.php page. Should this be blank?
Figured it out
The rating.php isn’t necessary for functionality, but is optional if you’d like to run a ratings system on various pages/content. Thanks again!
Okay Thanks MM
hey how to fix this Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a1558163/public_html/like/update_box.php on line 5
Warning: Division by zero in /home/a1558163/public_html/like/update_box.php on line 14
when is his will be a WordPress plugin?
You c’ant use this script with a video site,why
you work so hard as you can do the same with
a snippet php and a text file
well you need a hack code to hack ie9 from scratch
Here how you can fix it.
example: position:relative top: -10px\9;
This is hack for ie9 browser.
Just add \9 in the end of string
“single user can rate once”? You are using $userip = $_SERVER['REMOTE_ADDR']; that can only get the proxy ip, not client ip what come after a proxy. So if my friend (who has same local network with me) voted, so I can not vote.
And how to apply this for multi urls?
[...] View Tutorial [...]
Can you please tell how to setup the database, I get database error
why my like cannot increase?
Do NOT try and use google hosted jquery versions 8.0 and up. Firefox and IE will not work and it drove me crazy for days. Finally I used an older version of jquery and everything works beautiful cross browser. Hopefully this saves someone else the trouble I went through…