Building a 5 Star Rating System with jQuery, AJAX and PHP

Building a 5 Star Rating System with jQuery, AJAX and PHP

Tutorial Details
  • Difficulty: Intermediate
  • Technologies: JavaScript, PHP, HTML, CSS
  • Estimated Completion Time: 30 Minutes

In this tutorial, you’ll learn how to build a rating system with AJAX, PHP, and jQuery. Votes will be recorded and updated in real-time with the magic of AJAX, and we’ll also leverage the power of PHP so that you don’t even need a database!


Step 1. Building the HTML

We’re going to create a simple page that lists two movies, and allows you to rate them. This means we need the stars to show the current rating, and to allow voting. We also want an area to show the total votes cast, and the current rating down to one decimal place.

Let’s take a look at the HTML/CSS

        <div class='movie_choice'>
            Rate: Raiders of the Lost Ark
            <div id="r1" class="rate_widget">
                <div class="star_1 ratings_stars"></div>
                <div class="star_2 ratings_stars"></div>
                <div class="star_3 ratings_stars"></div>
                <div class="star_4 ratings_stars"></div>
                <div class="star_5 ratings_stars"></div>
                <div class="total_votes">vote data</div>
            </div>
        </div>
        
        <div class='movie_choice'>
            Rate: The Hunt for Red October
            <div id="r2" class="rate_widget">
                <div class="star_1 ratings_stars"></div>
                <div class="star_2 ratings_stars"></div>
                <div class="star_3 ratings_stars"></div>
                <div class="star_4 ratings_stars"></div>
                <div class="star_5 ratings_stars"></div>
                <div class="total_votes">vote data</div>
            </div>
        </div>
    

Notice how there are no graphics in this HTML? They’ll be added with CSS. We’re just using the HTML to create the framework that the widget works from. Now it’s time to start adding CSS.

        .rate_widget {
            border:     1px solid #CCC;
            overflow:   visible;
            padding:    10px;
            position:   relative;
            width:      180px;
            height:     32px;
        }
        .ratings_stars {
            background: url('star_empty.png') no-repeat;
            float:      left;
            height:     28px;
            padding:    2px;
            width:      32px;
        }
        .ratings_vote {
            background: url('star_full.png') no-repeat;
        }
        .ratings_over {
            background: url('star_highlight.png') no-repeat;
        }
    

This first part of the CSS accomplishes a few things:

  • Gives the default ‘empty’ start to each star location
  • Sets up classes for filled in stars, and highlighted stars
  • Defines and styles the stars’ container.

You can either use the graphics provided in the download, or make your own. There needs to be a graphic for each of the three states: empty, full, and highlighted.

Next we add a little more CSS to position the total votes box, and center the widgets so the page matches the graphic at the start of this section.

        .total_votes {
            background: #eaeaea;
            top: 58px;
            left: 0;
            padding: 5px;
            position:   absolute;  
        } 
        .movie_choice {
            font: 10px verdana, sans-serif;
            margin: 0 auto 40px auto;
            width: 180px;
        }
    

Step 2. Adding the UI Interactivity

At this point, we have a very plain looking bunch of empty stars, but they don’t do a whole lot at this point. This is where jQuery comes to the rescue.

Our first step is to add mouseover and mouseout handlers for the stars. We need to highlight the star the mouse is over, and all the preceding stars.

        $('.ratings_stars').hover(
            // Handles the mouseover
            function() {
                $(this).prevAll().andSelf().addClass('ratings_over');
                $(this).nextAll().removeClass('ratings_vote'); 
            },
            // Handles the mouseout
            function() {
                $(this).prevAll().andSelf().removeClass('ratings_over');
                set_votes($(this).parent());
            }
        );
    

We’re taking advantage of jQuery’s powerful .prevAll() and .nextAll() methods to get the stars preceding and following the currently moused over star.

The code above then adds and removes the classes to make the stars under the mouse and before ‘highlighted’, and the stars after ‘not highlighted’.

What about set_votes() ?

This is a function that checks which stars should be in the ‘full’ state, and ties in closely with the next step, where we grab remote data from the server.


Step 3. Retrieving Data from the Server

Our stars highlight when you move the mouse over them, and that’s a great start. But what about the red stars showing the current vote? To reach this step, we need to both get the information from the server, and write some JavaScript to handle that data.

        $('.rate_widget').each(function(i) {
            var widget = this;
            var out_data = {
                widget_id : $(widget).attr('id'),
                fetch: 1
            };
            $.post(
                'ratings.php',
                out_data,
                function(INFO) {
                    $(widget).data( 'fsr', INFO );
                    set_votes(widget);
                },
                'json'
            );
        });
    

This code block – actually all the JavaScript – goes in a document.ready block. This particular code executes right away. It queries the server and gets some information on every vote widget on the page.

First we set up an object, out_data, to contain the information we’re sending to the server. Our PHP script expects to see ‘fetch’ when just grabbing data, so we include it here. We also include the ID of the widget, which lets the server-side script know what data we’re after. When the call back function fires, it contains a JavaScript object that looks like this:

        {
            "widget_id"     : "r1",
            "number_votes"  : 129,
            "total_points"  : 344,
            "dec_avg"       : 2.7,
            "whole_avg"     : 3
        }
    

The .data() method is a bit of jQuery magic that allows you to associate arbitrary data with a DOM
object.

If you look closely at the code, you’ll see we’re taking that object (stored in the variable INFO) and
doing something with it via the .data() method.

The .data() method is a bit of jQuery magic that allows you to associate arbitrary data with a DOM
object. In this case, we’re storing the data in the widget div. It can be accessed later like this:

        $('#one_of_your_widgets).data('fsr').widget_id;
    

set_votes(), Finally.

After the data has been returned from the server, its handed off indirectly to set_votes().

        function set_votes(widget) {
        
            var avg = $(widget).data('fsr').whole_avg;
            var votes = $(widget).data('fsr').number_votes;
            var exact = $(widget).data('fsr').dec_avg;
            
            $(widget).find('.star_' + avg).prevAll().andSelf().addClass('ratings_vote');
            $(widget).find('.star_' + avg).nextAll().removeClass('ratings_vote'); 
            $(widget).find('.total_votes').text( votes + ' votes recorded (' + exact + ' rating)' );
        }
    

The first three lines are for readability, as those variable names are pretty long. So let’s take a look at what’s happening here.

Line 7: ‘avg’ is a whole number, representing the rounded vote average of this widget. Because it’s
a number 1-5, we can use it to find the proper star in the widget, and turn it, and the
preceding ones to our ‘filled’ graphic. Notice the use of .andSelf() to include the star that
we’ve selected.

Line 8: This is quite similar to line seven, but we’re removing the filled graphic from later stars. This
is necessary in case the average for this widget has gone down since the last vote.

Line 9: Here we’re updating the grey box underneath the widget, which shows a more precise rating,
and lets a visitor know how many votes have been cast.


Step 4. Let the Voting Begin

The final step for the UI is to enable voting. We’re going to add a click handler to each of the stars. This click handler will be responsible for sending the vote data to the server.

Here’s the click handler:

        $('.ratings_stars').bind('click', function() {
            var star = this;
            var widget = $(this).parent();
            
            var clicked_data = {
                clicked_on : $(star).attr('class'),
                widget_id : widget.attr('id')
            };
            $.post(
                'ratings.php',
                clicked_data,
                function(INFO) {
                    widget.data( 'fsr', INFO );
                    set_votes(widget);
                },
                'json'
            ); 
        }); 
    

In this code block, we start out by creating some variables not only for clarity, but, in this case, so they can be used within the .post callback. Remember the click handler is assigned to the stars, so we also need that second variable, widget, to have the object containing the data.

First, we set up our outgoing data, which we place in the object clicked_data. We grab the class which includes a class name in the format of star_# telling us what vote is being given, and prepare to send that to the server, along with the widget’s ID.

The widget ID is the corner stone that this voting system relies on. It allows us to look up our stored data, and to easily show that data to the visitor.

Finally, on line line, we send this information to the server. The server will add the vote to the current totals, and send information back to the browser containing the updated data. The values displayed by the widget are then updated with set_votes().


Step 5. PHP: Creating the Class

Now that the UI is finished, we need to create a server side script to store and retrieve voting data.

We’re going to create a very simple class in PHP, called ‘Ratings,’ and use it to handle server requests for our rating system. There are only going to be two methods, plus the invocation. The use of our class will look like so:

        # New Object
        $rating = new ratings($_POST['widget_id']);
    
        # either return ratings, or process a vote
        isset($_POST['fetch']) ? $rating->get_ratings() : $rating->vote();
    

If you go back to section four, you’ll see we load the data with the variable ‘fetch’ set – that’s what we’re looking for here on line five. If its not set, then we’re processing a vote.

The first thing we’re going to look at is the begining of the class, and, more specifically, the constructor.

        class ratings {
            
            private $data_file = './ratings.data.txt';
            private $widget_id;
            private $data = array();
               
        function __construct($wid) {
            
            $this->widget_id = $wid;
        
            $all = file_get_contents($this->data_file);
            
            if($all) {
                $this->data = unserialize($all);
            }
        }      
    

serialize() and unserialize are a great way to easily store
PHP data structures on disk.

There’s a lot going on here in very few lines, so I’m going to cover the important bits.

Line 3: This needs to be set to a text file you’d like to use to store your data. We’re not using a database for this project, although you easily could. A simple file will suffice for our needs.

Line 7: The constructor. This is called when we create our object, and immediately stores the ID of the widget.

Line 11: We try to load the text file. If the file doesn’t exist, fine, but on some systems you’ll need to create it ahead of time and give it the proper permissions for PHP to be able to read and write to it.

Line 14: This line is important. It takes the data from the text file – if there is one – and unserializes() it. The file contains a complex PHP array that’s been converted to a plain text representation, via serialize(), allowing us to store it and read it back in as an array later.


Step 6. The get_ratings() Method.

This method is called either on its own, or from the vote() method. It finds the data for a particular widget ID and returns it to the requesting page, in JSON format.

    public function get_ratings() {
        if($this->data[$this->widget_id]) {
            echo json_encode($this->data[$this->widget_id]);
        }
        else {
            $data['widget_id'] = $this->widget_id;
            $data['number_votes'] = 0;
            $data['total_points'] = 0;
            $data['dec_avg'] = 0;
            $data['whole_avg'] = 0;
            echo json_encode($data);
        } 
    } 
    

This only looks complicated – it’s actually pretty simple. The first thing we do is check if the array stored in $this->data has a key matching our widget ID. If it does, we just return that information, because that’s the widget data the page was requesting.

We don’t have to do anything to that data because its already in array form. $this->data is just an array of arrays. We encode the array we want with json_encode() and send it back to the browser.

If there’s no data for the widget ID we’ve requested, we create a record with all zero values, and send it back to the browser.

Step 7. The vote() Method

Next, we need to create a method to handle incoming votes. When the method finishes, it has to call get_ratings() to send the updated information back to the web browser.

The Method Start

        public function vote() {
            # Get the value of the vote
            preg_match('/star_([1-5]{1})/', $_POST['clicked_on'], $match);
            $vote = $match[1];   
        
    

The first thing we do is get the value of the vote. Remember that somewhere in ‘clicked_on’ is a class name in the format of star_#. "star_4", for example. To get that value, we’re using a regular expression and capturing the value of the number to $match[1].

The method Middle

    
            $ID = $this->widget_id;
            # Update the record if it exists
            if($this->data[$ID]) {
                $this->data[$ID]['number_votes'] += 1;
                $this->data[$ID]['total_points'] += $vote;
            }
            # Create a new one if it does not
            else {
                $this->data[$ID]['number_votes'] = 1;
                $this->data[$ID]['total_points'] = $vote;
            }
    

Here we store $this->widget_id into $ID for clarity – the following code gets a bit rough on the eyes without it.

We check if information for this ID exists, and, if so, we add a vote to the total vote count, and add the points from the vote received. This is a running total of all votes; so if one person gives five stars, and another, three, that’s eight points total.

If the record doesn’t exist, we create one, with one vote, and just the points from the incoming vote.

Finishing Up

  
            $this->data[$ID]['dec_avg'] = round( $this->data[$ID]['total_points'] / $this->data[$ID]['number_votes'], 1 );
            $this->data[$ID]['whole_avg'] = round( $this->data[$ID]['dec_avg'] );
                  
            file_put_contents($this->data_file, serialize($this->data));
            $this->get_ratings();
        }
    

Once we’ve updated the vote and point totals, we have to calculate both the average expressed as a whole number, and to one decimal point. To avoid having to do the math twice, we first calculate the average to one decimal on line one, and then round that off to a whole number, on line two.

On line four, we’re storing the changed information back on disk after processing it with serialize(). Once the data is safely stored away, we call $this->get_ratings() to send the new, updated information to the browser.


Conclusion

For the sake of simplicity, this isn’t a 100% complete solution. To extend this project, we should store a cookie to make sure people only vote once, or even record the IP address. It’s also possible that two first-votes couple happen simultaneously, and only one may be recorded. It is, however, a great start, and is more then suitable for keeping track of votes on a few handfuls of items on your website. Thoughts? Thanks for reading!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Roland

    Would a css sprite not make more sense for starters? Would eliminate the flash of having to download the image when you hover.

    • http://www.pixeloution.com Erik Wurzer

      @Roland – there are actually several things I would have liked to add, and sprites is on that list, But I didn’t want to add certain things without explaining them, and I felt like this was getting long, especially for my first tutorial.

  • Click Happy

    So easy to stuff the ballot ;)

  • Andrea

    An issue is that, that anyone can vote as many times as someone wishes..

    • http://www.jeffrey-way.com Jeffrey Way

      I think he mentioned that at the end of the article. I might ask him to release a Part 2, to implement some kind of cookie to prevent this. :)

      • http://www.deluxeblogtips.com Deluxe Blog Tips

        Yes, we can check the IP address or cookie to make sure someone has voted or not. The WP-Ratings plugin can be an example though.

  • http://tvfedor.ru zerkms

    @Andrea

    Imho the main idea here is to teach how to build star rating system and not the-best-secured-all-in-one-whatever-rating-system

  • http://www.ecustom.ca LC

    Very impressive.

    Regarding the other comment, I think I read somewhere that sprites are actually relatively ineffective now.

    Also, does anybody know when CSS3 will be made standards, I’m guessing 2-5 years?

    • http://www.delucamarketing.ch NetHawk

      Can you be more specific regarding sprites? Why should they be relatively ineffective? Never heard about that and can not think of a case where sprites would be less effective than single images. Of course, they have some restrictions (block elements, ideally with fixed h or v sizes), but I still see them as a good choice to reduce http requests.

  • Dasani

    thank you for the tut. But how do we prevent visitor from voting 100 times?

    • Zoran

      When user clicks on voting, check for cookie in his browser if he has already voted, if there is no cookie, then just let him vote and insert cookie in his browser, otherwise give him message that he has voted already. It’s simple logic, plus you can implement database here, endless possibilities if you sit down and think little bit, it will also help you become better developer if you are trying things on your own instead of waiting for someone else to do it for you.
      Just note here, you can get the cookie with js and php too.

      • Ryan

        IMO, the best way is to record the IP address in the database. That way it can never be cleared like a cookie, unless of course someone hacks into your database.

  • http://www.blackjet.ca stolkramaker

    Great tutorial, but definitely written for the developer with less emphasis on the designer + user experience.

  • http://www.jsxtech.com Jaspal Singh

    .
    Nice tutorial for Beginners.
    .
    Like others say – use Sprite instead of downloading images on hover and restrict the no. of voting from 1 IP.
    .
    Thanks for sharing.
    .

  • http://www.waynejohn.com Wayne John

    Wonderful walk-through for those trying to learn a nice feature for their toolbox.

    Good adds Jaspal, that’s phase 2 right? ;)

  • http://jason.karns.name Jason

    I think the most important thing missing from this tutorial is JavaScript-off functionality. It would have been a simple matter to make each star a link pointing to your server-side service to tally the votes. It’s a nice tutorial, but I think we need to move beyond these tutorials that leave big usability and accessibility issues as ‘exercises for the reader’.

    That’s aside from the fact that making it function without JS would force a cleaner server-side architecture of the service layer.

  • http://www.cbesslabs.com Bratu Sebastian

    Actually, I believe the tutorials should have different knowledge levels, that’s the point of a tutorial site, if we make more and more specialized tutorials, nobody new would learn to do something simple.

    I believe having to learn something simple and understanding it to the level of being able to do something similar is more important than giving out free solutions with all the ready assets. I understand the need to get more and more complicated, but how much can we advance ? To the point that we will no longer be able to make a simple alert(‘hello’) command ?

    You give people a finger, and they take your whole hand :) Sorry for the rambling, I haven’t slept in 12 hours.

    Great tutorial, appreciate it and shut up !

  • David C

    It really is to bad that ‘certain’ browsers have poor font rendering by default. Otherwise, you could use fonts to render your stars. ★ is the star entity.

    Oh well.

    • David C

      Bah! It actually translated it (which is cool, but not what I wanted).

      You encode stars with & # x 2605; (no spaces between the ampersand, sharp, x or numbers and semi-colon)

  • http://1click.at Michael Pehl

    I like it. I would vote 5 stars :-)

  • test

    testing fuck

    • Djkanna

      What? You need a tester one first O.o

      To the author, I like this nice work! :)

  • Ravi Ahuja

    Nice 1..thanx..!!

  • Zoran

    Hey, thanks for this, it’s a good starting point, adding ability for only one user to add rating should be easy. I also didn’t know about andSelf jquery function, so thanks again.

  • http://lowgravity.pl Kamil

    Do You people can’t read what is written? This is a “starting” tutorial with a lot of “to do” in future.

    All You can do is complain and You can’t notice that in order to make fully-featured star rating it should be 5 times longer…

    but hey, You would have written better by Yourself….

  • http://jamie@swimandsing.com Jamie

    Tutorials are all about learning. I support tutorials that make the reader think.

    I helped run an online voting system for 3 years. This tut helps the user deal with the issue of multiple voting attempts by a single user.

    This is not a free script site.

    Here is an issue we cam across: Many users would vote from the office sharing the same IP address with coworkers who would also like to vote.

  • http://babylon-design.com/ Shemu

    A good rating system must be a form ! And it must work with no CSS and/or no images and/or no JS. See a better way : http://www.babylon-design.com/exemples/jquery-stars/en

  • http://af-design.com/blog Erik Giberti

    A simple tweak should allow the star clicked to remain highlighted (like Netflix). If the intention is for that to happen, it doesn’t work for Mac Safari.

    Regarding the ballot stuffing: this is a demo showing how the UI can work, not how to ensure that someone can only vote 1 time. That’s fodder for an entire future blog post!

  • Doug

    You can click to stars continuously, and the vote raises continuously…
    2 ways to stop this: IP watching or using Jquery once method.

  • http://www.jordanwalker.net Jordan Walker

    Real nice tutorial with real implications for online applications.

  • Patrick

    Hm okay, just one way to do that. Well explained, but its a really bad idea to use jquery for _all_. Please, deactivate javascript in your browser and see what happens. All votings won’t be displayed, very bad. Better is to display the vote with php and use jquery to enhance the voteing procedure.

  • andi

    Horrible flickering of the stars when you mouseover them

  • http://websterdesigns.net Adam Webster

    Thanks for posting this. It will be very useful for a project that I am currently working on.

  • http://kylefox.ca Kyle

    Good UI tips, but this isn’t a very good way to calculate an overall rating of something.

    For example, an item with only 1 vote of 5-stars will have a calculated average of 5.0 (obviously). If you were to rank items based on ratings, this item would be a top-rated item.

    A better way to to calculate a confidence interval based on the number of votes. For example, you can be fairly certain an item with 1000 votes will have a more accurate rating than an item with only a handful of votes.

    Read this for proper calculations. http://www.evanmiller.org/how-not-to-sort-by-average-rating.html

  • Cathy

    i like it … effective and simple to follow… good foundation to build upon :) .. thanks !

  • http://www.epicwindesings.com Antonio

    Cool thanks for the tutorial, it’s not a foolproof method but it’s a pretty good basis and can improved upon with some work. I’ll have to give this a try when I get home. Plus it uses Ajax.

  • Kevin Woolery

    Good tutorial, and I’m not trying to be critical, just adding to the knowledge base, since I’ve built this exact type of system for sites that supported more than 500 million requests per month. As it’s been pointed out in previous posts, there are a few shortcomings. I’ll address both of them.

    First, there’s a problem with race conditions and serializing/unserializing the data to disk. If more than one person is voting for anything, it doesn’t have to be the same thing, and someone comes in at the same time to vote for something else, the states of the unserialized data in each process will differ for both requests, therefore leading to lost data. Even in non-trivial, semi-popular sites, this becomes an issue very quickly. Using a relational database is a more reliable solution, since record, and table locking is provided to alleviate this problem, and provide a level of confidence with regards to data consistency. You can get tricky with the file based solution, and solve the race condition, however, it becomes very sticky, and complex, and will seem more worthwhile to use a relational database in the beginning. Note, that as the system gets larger, it makes sense to look into a middle level solution, such as memcached/(memcachdb for disk persistence), and an asynchronous DB write solution.

    Second, the system allows for users to vote more than once. There have been various approaches to solve this, but most haven’t addressed some major issues with the either/or solutions. The first either/or solution is to set a cookie, and check for that cookie before allowing someone to vote. There are multiple problems with this, since a user could still game the system by disabling cookies altogether, or by writing a script that doesn’t accept cookies. In addition to not accepting cookies, it becomes unreasonable for your site to track individual votes across cookies. There is a limit on the amount of data that can be stored as cookies for a site. The second either/or solution is to set the IP address along with the vote, and make sure that that IP address can’t vote again on the given item. This makes sense, but it easily becomes an issue on non-routable networks where outgoing requests are NAT’d/proxied through a single network interface. This would allow only one vote per network, which would eliminate votes on large campus networks. The solution is actually a combination of the cookie solution, and the IP solution.

    When a user visits the page for the first time, a user identity entry should be created for an IP address, and a random user token. On the client side, a cookie should be set as a base64 encoded string consisting of the IP address, and the token. When the user votes, the cookie is passed along with the request. If the combination of IP address, and user token have not already voted on the item, and the IP address in the cookie matches the REMOTE HOST IP Address, then the vote can be counted, otherwise the vote should be ignored. If a cookie is not passed along with the vote, the vote should be ignored as well.

    It’s still possible to game the system by way of script, but this could be stopped on the backend by limiting the number of votes in succession from an IP address, but not blocking it altogether, so others can vote from the same network. This type of system becomes about identifying patterns in voting that look inauthentic, and dropping/ignoring them, but that’s a discussion for a different day.

    • Erik Wurzer
      Author

      Keven,

      Thanks for your input. I had thought of most of these considerations, and a few more, but I felt that a tutorial covering the perfect system would be too long and involved, so I took a number of shortcuts.

      Would I have like to included using database storage? Sure. I could have also used flock to prevent the race conditions you’ve described. I could have also included a part using and explaining sprites for the images, and even made it degrade gracefully without javascript.

      This wasn’t meant to be a 100% finished solution, it was meant as a teaching exercise; maybe next time I’ll ask if I can present such a complex subject over multiple tutorials and build it right.

  • http://gotweedheads.com markaid

    Thank-you for this tutorial, Erik – a very elegant voting system and appreciate the explanations coming after the code. You’ve managed to synthesis a very complex structure into it’s essential building blocks!

  • http://ikashits.com qamar

    thanks, nice,

  • http://variable3.com/blog/ Harsha M V

    brilliant tutorial. wonder how to implement this into the cakephp framework.

  • http://www.dev-hq.co.uk Joe

    Has flaws (as yourself and others have pointed out), but overall, nice work!

  • http://tutorialblog.info/ tutorial blog

    thank. i like it. because it very useful.

  • http://www.szul.eu Pozycjonowanie Olsztyn

    Very nice tutorial :)

  • http://freegames.graphicedit.com/ FG

    Very nice tutorial

  • BP

    Can somebody please post the modified code using a MySQL database plus the utilizing the cookies to avoid repeated votes by the same user? Thanks.

  • sumit

    the problem with this script is that you can vote unlimited times

  • http://withrock.iblogger.org nobody

    good~

    i learned more from your site.

    though my english is poor.

  • http://www.design-ludwig.de Ludwig Design

    Thats exactly what i’ve searched. Thank you Nettuts!

  • Michele

    Hello,

    I have downloaded the source files and I have uploaded them on my site to make a test, but the project does not work. Can you help me?!…

    PS: Great work :D

  • http://www.mitsoft.sk MitSoft

    Hi,
    I have problem with this code. When on page is alredy running lightbox system for viewing images, rating system is not working (only shows the stars). Please visit http://www.ubytovanie-podhajska.info/Andrejka-I for view.

    • Petro

      Andrejka, go to school! Do not bother creative people!

  • John

    What a point? For that small functionality develop that much. And have jQuery library if you is not using it for your website, it’s 50k compressed. I think it much better to use hosted service like rating-system.com

  • Marchel

    hi… i found that u saved it on .txt file.. how if i want to save it to mysql ? like i want to have rating system for reviews posted.. thanks..

  • http://www.fubarlegion.org/reviews/zombies.html Dave G

    Hi, Im having a slight problem with this. I have bumpbox and mootools running as well. I can have the rating script work or other, but not both? Ive tried in vain to search for an answer but i just cannot find anything to help….

    Any ideas please, im at my wits end with this…. :(

    Regards

    Dave :)

  • http://shrikrishnameena.blogspot.com Shrikrishna Meena

    Good tutorial on ratings!!! But little complex or I’m little lazy to understand this.

  • Al

    Nice one!!

    Perhaps there should be a follow-up on this one whereyou could incorporate sprites and rich snippets for the ratingto be included in SERP’s.

  • http://www.free-sculpts.com Fred

    Very easy to implement and very functional!

    The JQuery and PHP is very simpe to understand and use given the complexity of this task. Took me less than 1 hour to implement, and most of that was getting PHP up and running. I think for a tutorial, this is a ‘complete’ solution, as it includes the PHP file system, so it runs with AJAX right out of the box.

    With the example PHP and multiple vote HTML you have given, it is easy to change to a database driven solution with cookies and IP address matching.

    5 stars!

  • http://www.bbbcubed.com Craig

    Thanks for the great tutorial…have tried a few others, but this was the best one, appreciate the hard work that went into makingit.

    Now all 168 of my sites downloads have rating stars next to them!

  • http://www.bartekszkurlat.se Bartek Szkurlat

    Great tutorial.