Unobtrusive AJAX Star Rating Bar

Unobtrusive AJAX Rating Script

What It Is

This is a rating bar script done with PHP and mySQL that allows users to rate things like can be done on Netflix or Amazon, all web 2.0-like with no page refresh. It is a major improvement on the previous version because it is now unobtrusive, meaning that if Javascript is off it will still work (although the page will refresh). You can also set the number of rating units you want to use (i.e. 4 stars, 5 stars, or 10 stars) on a rater to rater basis (see samples below or read the docs). A few other changes were made as well – see the docs for details. Note that this script isn’t tied to any specific system (such as WordPress), so you should be able to adapt it to your situation without too much trouble. What are you waiting for? Check the demos.

Based on work found at Komodo Media and Climax Designs. There is also another AJAX version of a rater on this page: Yvo Schaap

Creative Commons License Good people of the Internet: This work is licensed under a Creative Commons Attribution 3.0 License. Please give credit where it is due, whether it is to me or the people upon whose work I based this script, and don’t claim this work as your own! Please consider making a donation – even $0.50 or a buck. That would be so freaking cool of you. Donate button located below.

If you have any problems downloading the file, first make sure you don’t have any over-crazy firewall protection on. When you can’t grab the file that is USUALLY the culprit. And you have to download it from this domain. I don’t like direct links from other sites. If that doesn’t work, .


Whatchoo Talkin’ ‘Bout

v 1.2.2 Updates (March 18, 2007):

Sorry for the quick release between version 1.2.1 and version 1.2.2. I needed to update the script this page was actually using (it was still using the oldest version) because someone kept farting around with the ratings here. Hopefully, that won’t happen now that this page is using the newest version of the script. Also, because I’m running this site with Wordpress, I found it was a pain in the arse to go in and change the DB queries manually, so I just altered the script to work with Wordpress out of the box by changing what needed to be changed.

  • Added: prefixed DB calls with $rating_dbname for better separation from other scripts. This will really help with Wordpress installs – As of 1.2.2 – I don’t think you need to do any special tweaks any longer.
  • Updated: changed some variable names so as not to confuse with other scripts

Notes

Basic changes, modifications, and answers to common questions. I will move all changes, modifications, and general advice to the forums, where they belong. (The forums are NOT live right now, but coming soon…)


With a Little Help From My Friends

HEY MONKEYBOY. YEAH, YOU. One very good reason that I DO NOT offer tech support on this script, offer CSS lessons, teach HTML, or give anyone any idea how to fix this silly thing in IE 6 – all things that google is so good at if you know how to type, is because I make next to nothing on this script.

I spent a lot of spare time polishing this thing up and trying to make it more useful. If the late nights I spent tearing my hair out trying to determine why Internet Explorer won’t allow dynamic insertion of an “onclick“ into a link using setAttribute has saved you any time at all, or if you just think it looks purty, consider a little donation. C’mon, you know there must be a couple bucks just sitting in your PayPal account that you’ve forgotten about!

If you come up with anything more interesting or better developed than what I have here, you’ll have to drop a line in the forums (which, I’m telling you, are coming soon). Suggestions are welcome and information about vulnerabilities or egregious violations of PHP best practices is most welcome as well – just be nice. And remember, spread some good karma: donate today!

Whither Wall of Fame & Live Samples?

These have been quietly removed. All I got was an inbox full of needy people looking for linkage to their site, that may or may not have been shoddy, and may or may not have actually used the rater in such a way that it looked good. There was way more noise than signal there, and I didn’t need the headache. Thanks to everyone who has donated in the past, and will donate in the future. It’s much appreciated!


Demos

1a Rating: 3.9/5 (19025 votes cast)

2x Rating: 4.0/5 (11114 votes cast)

  • Currently 3.23/4
  • 1
  • 2
  • 3
  • 4

3 Rating: 3.2/4 (16655 votes cast)

4x12abc Rating: 7.3/10 (20737 votes cast)

  • Currently 6.00/10

5x12abc. Rating: 6.0/10 (1 vote cast) This is 'static'.


Comments are closed for the Star Rater!

Sorry, but comments have been closed for this script. You can now read all about it (and post your questions and advice) in the forums! (Coming VERY soon...) Pretty much all the info you need to fix or upgrade the Star Rater version 1.1 is found in the existing comments. And again, sorry if you feel like you're getting dissed, but I can't offer help on this script. I just can't. I can't give lessons in CSS, either. I may be able to pop in on the forums from time to time. Thanks for your understanding.


300 Comments

  1. 211. Mark Fresh

    December 29th, 2006

    After looking through all these comments it would be great if someone could put up a link to a synopsis of changes/tweaks/hacks (the same as Eric as done on #160) on a site that doesn’t strip out php scripts.

    It should include:
    How to make it work with Wordpress (to solve 80% of issues)
    How to include auto insert of IDs
    How to format the presentation of the stars
    A reminder to check the paths to all files if you have changed the original file paths
    What permissions the database user stated in _config-rating.php should have
    Options such as a top ten script (see #6 Jason G)
    Setting up an IP block and/or cookie block
    How to add “no follow” to href
    What settings within PHP.ini may effect this
    How to make the css in ratings.css override your site’s css file
    A big up respect to Ryan for creating this script in the first place

  2. 212. joaquin

    December 29th, 2006

    very good script, congratz

  3. 213. c. vd berge

    January 02nd, 2007

    while setting up this wonderfull script Im running into a kinda weird problem:
    when I click on a star, it will ‘hang’ while showing the working image, but when I actually use the direct url to the db.php (with right click -> open in new window) it works perfetly!?

    what can be causing this? Im kinda lost at the moment…

    (page is http://www.wistudat.net/wistudat_test.php and the db.php is in http://www.wistudat.net/rating/ en yes, I adjusted the paths in the files ;) )

  4. 214. Joe

    January 03rd, 2007

    Is there someone that I can pay to install this for me. I don’t work under the hood. Thanks

  5. 215. Mridang Agarwal

    January 03rd, 2007

    Hey Guys,
    I loved the script. Its was awesome. Anyone know where i could get the Golden stars but rendered on a black background. My web page has a black background and these stars don’t seem to have a black background.

  6. 216. Mridang Agarwal

    January 03rd, 2007

    hey Joe,
    I’d be willing to fix it up for you. Mail me at mridangagarwal@gmail.com

  7. 217. c. vd berge

    January 04th, 2007

    @Mridang,

    Just edit the images in the images map. replace the white with black and you’re done ;)

  8. 218. Mridang Agarwal

    January 04th, 2007

    Hey Berge,
    If i just edit it in Photoshop and fill the while with black. I get really ugly looking stars. The borders look really weird. Could you do it for me if it’s not too much to ask. I don’t know much about Graphics more into the coding thingy.

  9. 219. Jay

    January 04th, 2007

    @mridang and @berge

    Mridang is right; changing white to black will not work. What we need is a transparent background so the only things that show are the stars.

  10. 220. Roger

    January 06th, 2007

    Nice graphics! Nice script, but i cant get it too work. I read the readme.txt file. I inserted my db / user / pass in the _config-rating.php file. But when I load index.php and I vote at some it said thanks for voting score 3.0/5 or something but the stars are all empty and when I refresh the page, the vote is gone. Im using WAMP5 on localhost, can anybody help me?

    Greetings

  11. 221. Roger

    January 06th, 2007

    I’m sorry for my last post, I didn’t read the readme file well at all. I forgot to insert some values in `ratings`

    Sorry

  12. 222. Roger

    January 06th, 2007

    I made some simple script to get the rating system ready for $iPollsReady ratingsystems;

  13. 223. Roger

    January 06th, 2007

    // php tag open

    // make sure this file is in the same directory as _config-rating.php

    require ‘_config-rating.php’;

    $iPollsReady = 401; // Makes 400 polls ready..

    for ($i = 1; $i

  14. 224. omur uluask

    January 06th, 2007

    hey,

    it is another rating system for wordpress

    http://www.lesterchan.net/portfolio/programming.php (Wp-Postratings 1.05)

  15. 225. opera

    January 06th, 2007

    I had some troubles in Opera as well (not with your original script, just after I had integrated it into my site), and it seems Opera has some problems with the path to rpc.php. I had changed my URLs using mod_rewrie so… but it works now when I’m using an absolute path like;

    xmlhttp.open('get''http://localhost/site/dir/rpc.php?j='+vote+'&q='+id_num);

    Cool script btw !

  16. 226. Oliver

    January 07th, 2007

    Hey Mridang Agarwal and
    I just havec the same problem you get. My background is 999 and the stars show up on a white background. I tried to change things in PS but it does not work. If you get the stars on a transparent background or any other solution , please share, i ll be happy to implement it as well

    Thanks

    Olivier

  17. 227. Oliver

    January 07th, 2007

    hello, forget my last question, I worked this out using icons from famfamfam but now I have a more serious problem with this error message:

    script ‘/home/httpd/vhosts/site.com/httpdocs/rpc.php’ not found or unable to stat, referer: http://site.com/test.php

    test.php works but when I try to cast a vote, it hangs on the loading gif. The connection to the db works as it reads correctly the votes I amnually inserted in it

    Anyone has an idea?

  18. 228. Joe

    January 09th, 2007

    Hi do any of you have any good stars that have no back ground so will work on any colour page.
    How would i make it so it is disabled on some pages so u just get the stars but you cant vote and you dont get how many people voted aswell so realy you just get the stars.And on this site useing this script http://www.cssremix.com/ when you go to vote you get this [removed]sndReq(’how many to vote’,’id’,’ip’) instead of
    db.php?j=number of stars&q=id&t=ip&c=how many to vote
    how did they do that and how did they get it to show e.g. 3.4 then stars if any 1 could help thanks i will chck back here every day or if you have msn plz add admin@joesgraphics.co.uk thanks i luv this script.

  19. 229. Jonathan

    January 10th, 2007

    Great Script !!!
    Works like a charm in Mozilla, but guess what? PRoblems in IE6.
    Even though I’ve selected 5 stars to display, IE displays
    all 10 stars. The rating is active on only 5 stars, but the rest are displayed as background images.

  20. 230. Djeck

    January 11th, 2007

    Why after pressing votings it is displayed, what has voted, and after updating page all on zero?

  21. 231. Marko

    January 11th, 2007

    What if I have a dynamic site and I want to include this rating system in over 1000 pages is there a way to make it so it automatically adds the fields in the database and writes to them?  I want to use the same include for all pages but all the pages will need their own unique rating system.

  22. 232. ryan

    January 11th, 2007

    @Marko: At least a couple places in the comments on this page are instructions for automating DB inserts.

  23. 233. Joe

    January 13th, 2007

    Ryan could you answer what i asked above please.

  24. 234. Vahrmeijer

    January 13th, 2007

    made some updates for the porting to MEDIAWIKI, the rating is now restricted to articles only (not frontpage / categories or other special pages)

    see:
    http://www.leerwiki.nl/How_to_port_Unobtrusive_AJAX_Star_Rating_Bar_to_MediaWiki

  25. 235. wayne

    January 15th, 2007

    I cannot get this to work, it’s displaying, and it’s connected to my data base, but when you click to vote it does nothing, please help someone.

    wayne

    this is were it’s at currently

    http://www.ncgolfers.com/raleigh-north-carolina-golf-course-bentwinds.php

  26. 236. aku

    January 16th, 2007

    really cool - love it. Im gona try and implement this with my existing DB.

  27. 237. nessie

    January 19th, 2007

    I cannot make this work. I’ve followed the steps posted by Vahrmeijer for mediawiki twice but I always get the same error:
    Fatal error: Call to undefined function wfRunHooks() in F:ProgramasXAMPPhtdocswikiincludesSpecialPage.php on line 173

    I’m a newbie in PHP so the only idea I had was to include the required file, but after that I continue having the same problem with different files until I get different errors with functions that cannot be solved including files, so I think that something is wrong in the previous process. Is there any important step missing in the post? Any ideas to solve it?

  28. 238. Max Stein

    January 21st, 2007

    I need help making this work on my automated game website cms so it displays a unique rating system on every page, but the code doesnt display anything after going through my template system, it is having trouble due to the mixture of html and php , does anybody know how I could rewrite drawrating.php so its 100 percent php or know of any other solution to my problem? Please ive been trying for monthes. My website is www.allgamesallfree.com .

  29. 239. Pete

    January 21st, 2007

    was there ever a solution to this problem first posted by Berge on January 2nd:
    “while setting up this wonderfull script Im running into a kinda weird problem:
    when I click on a star, it will ‘hang’ while showing the working image, but when I actually use the direct url to the db.php (with right click -> open in new window) it works perfetly!?

    what can be causing this? Im kinda lost at the moment…”

    just to add: it also works perfectly when everything is in the same directory. i’ve combed through all the code many times and i’m pretty sure i’ve change all the appropriate paths. thanks in advance

  30. 240. sexydave

    January 22nd, 2007

    Hi,

    great mods! But it could reaaaallly nice to add a Cookie Base Addons too cause the loged IP aren’t deleted after x time from the MySQL DBase.

    Maybe a Browser-Cookie or Mysql-Cookie… I got a preference for MySQL-Cookie since not everyone enable their cookie.

    Do you tink it could be done?

    regards,

Sorry, comments are closed.