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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | $(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)); }); //////////// }); }); }); |
Related Posts :
36 to “YouTube Style Rating/Voting System using jQuery, Ajax and PHP. Ever Best Tutorial !”
Post comment
Who Am I

Zeeshan Rasool
Software Engineer - PHP
Lahore - Pakistan
Skype: zeeshan-rasool
gTalk: zishan.rasool85
Categories
- AJAX (24)
- Codeigniter (16)
- CSS (7)
- Facebook (8)
- Joomla (1)
- JQuery (34)
- Miscellaneous (3)
- Mootools (1)
- MySQL (4)
- PHP (43)
- SEO (2)
- Technology (6)
- Twitter (1)
- Web Development (58)
Archives
- August 2010 (7)
- July 2010 (9)
- June 2010 (9)
- May 2010 (8)
- April 2010 (17)
- March 2010 (13)
- February 2010 (3)
Tags
99points
adobe
AJAX
ajax pagination
ajax rating
ajax tutorial
captcha
Codeigniter
codeigniter 2.0
codeigniter recaptcha
CSS
css tutorials
curl
dreamweaver cs5
Facebook
Facebook. PHP. JQuery
facebox
farmville
ffmpeg
flv
google api
hacking
image gallery
Joomla
JQuery
jQuery Sliding
Jquery tutorial
mafia war
Mootools
MySQL
Payment
PHP
php curl
Poll System
recaptcha
RSS Feed
SEO
simplepie
socail networking
ssl
Tutorials
Twitter
Web
XSS
youtube
Comments
- Super Ajax Polling/Voting System using JQuery, Ajax, PHP and MySQL | Bodeezy Bux on Ajax Rating System: Create Simple Ajax Rating System using jQuery AJAX and PHP.
- Adam on Create Animated Tabs using JQuery and CSS.
- ZeeShaN on Reloaded: Facebook Style Wall Posting and Comments System using jQuery PHP and Ajax.
- Marco on Reloaded: Facebook Style Wall Posting and Comments System using jQuery PHP and Ajax.
- Facebook Style Wall Posting and Comments System using jQuery PHP and Ajax | Programmer Heaven on Facebook Style TextArea with Wall Posting Script using jQuery PHP and Ajax.
ZeeShaN





Thank you for this nice tutorial, Its 100% same as youtube, thanks again…:)
I was searching over internet for a best rating system which would help me to create awesome stuff, here I got this… thanks 99points
oopes.. Its awesome, but how can I use it in my ASP.net website
very nice, good work
good work, little tricky
working fine I like toolip, We can make it little changed to youtube. Good work Zeeshan
Thanks to all my friends !
Hi, thank you zeeshan this is a really nice piece of work, I like your blog. its design and there are many good tutorials.
thank you zeeshan ….. great tutorial ………..
its amazing… I like it… It solved my problem
[...] YouTube Style Rating/Voting System using jQuery, Ajax and PHP. Ever Best Tutorial ! [...]
Great article, I will write an integration for VLD Personals on it and post the link here
@georgi thanks,
[...] http://www.99points.info/2010/07/youtube-style-ratingvoting-system-using-jquery-ajax-and-php-ever-be... [...]
Hi
I created the DB and files on a local server and get only the header “Youtube Style Rating/Voting System using jQuery Ajax and PHP. Ever BEST Tutorial” without the rating box or any other thing.
Where is the problem?
Hi, did you got any error? check source code in browser by right clicking and check is there any php error. Also I have included header footer so comment these two lines in index.php
Thank you ZeeShaN. I looking all over the internet youtube thumbs up, and finaly this is what I need. I download now and try to learn and recreate new one. Thank you again for sharing with us, it’s very helpfull.
you welcome dan,
Thank you very much for your great work, but i have a problem.
The downloaded script is different from this one here. I have installed it but i get many errors with :
Warning: Division by zero and Warning: mysql_fetch_array(): supplied argument is not a valid MySQL…
The database you write here is not like the sql file that i have downloaded.
Can you help me please?
Thanks you!
Hi tony, thanks and welcome. I have uploaded all data and it should be work fine because if there are any change in db then It is also updated in source files according to db. So I dont think this should be produce any error. How ever, Insert a fake record in db so that It shows first rating. Currently the db is empty there fore may be its giving error. Good Luck !
Oh man, Thank you so much for your fast reply. Now it’s working like a charm and I like it more than the other in 9lessons.info. This is complete and more sexy
.
But i still asking if no trouble for you. how can I integrate this script with a site with many pages?
I’m using a video site and want to give for every article and page the own rating.
Example where I should change the Id value!! In the database of the site I have already a Id table and the code to show it is $row[id]
Thank you again,
Best regards!
thanks tony, I always try to come out with some perfect type of tutorials. I just want all of my readers to share this blog as you can and help me out to make this effort successful. About your question: you need to attach article id with every rating. And get and insert records against that id. Good luck
hi ZeeShaN, where can i change the value of the Id in the youtube_rating table? Always show the same result forall the pages(id=1)
Hopefully you can help me because i want to include some code in the single plage(wordpress) and then automatically all the articles show the according rating system per id!
Thank you!
Regards!
Hi ZeeShaN,
Thanks for absolutely brilliant code. I am just experiencing one problem. This is that the text hovering above the “quickstat bar” is reversed. If I have ‘2 like votes’ it tells me 0 like , and 2 DISLIKE votes.. I am confused. It is like it has been reversed. Would be very grateful for help.
See here:
http://img641.imageshack.us/img641/4171/imghost.png
Thanks,
Lars
once again; nice wek
@edwin, Thanks
@Lars. Please check tooltip code This is revers there. The Heading is Like but variable will be dislike there. Just replace them in index.php
Thanks ZeeShaN, Would it be possible for you to tell me which row # the change in index.php should be. I am not too good at this. Thanks a milion /Lars
4734 dislikes, 1421 likes
Replace above with 4734 dislikes, 1421 likes TO 4734 likes, 1421 dislikes …
I hope you got it
[...] and voting script at 99Point.info I used animate() function of jQuery to get some stylish effect. When I create Youtube Style Ratings and Ajax Rating Many readers liked this and I thought I would give some stylish rating systems. [...]
Hi Nice tutorial.
Just as a thought, I am always cautious about using the IP address to check for multiple user inputs as I usually have more than one IP address that I use and I also share my ip address with others.
I have one at home and one at work and I take my laptop to the local internet cafe sometimes, so that would mean 3 ip addresses at least on my computer and I also access the internet through my phone. That would mean if I really wanted to I could get at least 4 votes for something, local coffee shops and wifi hotspots mean I could easily get more.
The flip side to that is also that I share my IP address at work and at home, so that could mean that I don’t get a vote from anywhere if others have already voted using the IP address I am on.
Just thought I would highlight that, but the voting system is great.
Thank G, you have pointed nice issue. Actually this time I am using IP for this voting system but If there is a site which required registration first before voting then we can do this thing easily by their email. So then we can save email address against that rating and we can check that If a user having email (example@example.com) already voted then we cant allow him to vote again.
I think Youtube is also using same thing with email or userID.
Hope it Works well
Regards
Zee
Thanks to share this code but could you tell me
why I see “Warning: Division by zero in /www/…/update_box.php on line 14 & 16″ ?
Is-it because there is no recording ? but how add one ? sorry for my poor English language
For exemple I added this via phpMyAdmin:
- id: 1
- up_rated: 1
- users_ip: 123.123.123.123
- down_rated: 0
but it seems wrong…
hi, Jessy, you should give down rated = 1 try that and let me know if it still give error
@ZeeShaN: Thanks for your reply… but there are always these 2 warnings / errors
May be, my php config could be the reason ?
Hi Zeeshan, A very nice example. but i want you help. i want to use this rating multiple times on a single page. For example, if we have 4 or 5 articles on one page and user can rate each article individually, Please tell me how i can do this. Please make an example for this also. i assigned Ids but its not working.
Please help me..
Regards
Usman
thanks usman, for liking my work. You can do this if you just make a full try, i have no example to show you I will try to make a post on this type of thing soon but not sure when.
I hope you will do it You just need to separate each rating with article ids.
Cheers