jQuery- Refresh a users current vote (star rating) with the average votes and avg. value
<p>I am using jRating plugin on my website. The plugin homepage is <a href="http://www.myjqueryplugins.com/jRating" rel="nofollow">http://www.myjqueryplugins.com/jRating</a></p>

<p>The plugin works fine as seen my website <a href="http://mashup2.sunnydsouza.com" rel="nofollow">http://mashup2.sunnydsouza.com</a>
The problem is I have a few requirements that requires tweaking with this jQuery plugin and am stuck bad.</p>

<p>An example of the code am using is as shown below.</p>

<pre><code>&lt;script type="text/javascript"&gt;
    $(document).ready(function(){
        $('.basic').jRating();

        $('.exemple2').jRating({
            //type:'small',
            length : 5,
            decimalLength : 0,
            step:true,
            onSuccess : function(){
                alert('Success : your rate has been saved :)');

            },
            onError : function(){
                alert('Error : please retry');
            }
        });

    });
&lt;/script&gt;


   &lt;div class="exemple2" data="4_2"&gt;&lt;/div&gt;&lt;div align="center" style="font-weight:normal;font-size:12px;"&gt;(10 votes)&lt;/div&gt;&lt;span id=vote_2&gt;10,votes,average : 4&lt;/span&gt;
</code></pre>

<p>I want is that whenever the user chooses a vote (say 3/5). the number of votes as well as the color of filled stars should update immediately to reflect the AVERAGE votes not the current vote.</p>

<p>Currently if there are already 10 votes and the average vote is 4/5. When the 11th user votes 3/5, the stars should refresh to show 3.5/5 and number of votes should show as 11 automatically.</p>

<p>How do I force to refresh the stars with votes of the AVERAGE vote and not the current vote and also update the span tag to reflect the changes</p>

<p>Please can someone help me out please!</p>

<p>EDIT: The server side code</p>

<pre><code>    &lt;?php
    include("/connection.php");
    $ip=$_SERVER['REMOTE_ADDR'];

    $aResponse['error'] = false;
    $aResponse['message'] = '';

    // ONLY FOR THE DEMO, YOU CAN REMOVE THIS VAR
        $aResponse['server'] = ''; 
    // END ONLY FOR DEMO


    if(isset($_POST['action']))
    {
        if(htmlentities($_POST['action'], ENT_QUOTES, 'UTF-8') == 'rating')
        {
            /*
            * vars
            */
            $id = intval($_POST['idBox']);
            $rate = floatval($_POST['rate']);

            // YOUR MYSQL REQUEST HERE or other thing :)

            //Verify IP address in ips table
            $ip_sql=mysql_query("select userip from ips where id =$id and userip='$ip'");
            $count=mysql_num_rows($ip_sql);

            if($count==0)
                // if request successful
                $success = true;
            else
                // else $success = false;
                $success = false;

            // json datas send to the js file
            if($success)
            {
                $aResponse['message'] = 'Your rate has been successfuly recorded. Thanks for your rate :)';

                // ONLY FOR THE DEMO, YOU CAN REMOVE THE CODE UNDER
                    $aResponse['server'] = '&lt;strong&gt;Success answer :&lt;/strong&gt; Success : Your rate has been recorded. Thanks for your rate :)&lt;br /&gt;';
                    $aResponse['server'] .= '&lt;strong&gt;Rate received :&lt;/strong&gt; '.$rate.'&lt;br /&gt;';
                    $aResponse['server'] .= '&lt;strong&gt;ID to update :&lt;/strong&gt; '.$id;
                // END ONLY FOR DEMO

                $result=mysql_query("select feed_vote from gp_feed_details where feed_id=$id");
                if($row=mysql_fetch_array($result))
                    if($row['feed_vote']==0)
                        $sql = "update gp_feed_details set feed_vote_count=1,feed_vote=$rate where feed_id=$id";
                    else
                        $sql = "update gp_feed_details set feed_vote_count=feed_vote_count+1,feed_vote=((feed_vote+$rate)/2) where feed_id=$id";

                mysql_query( $sql);
                // Insert IP address and Message Id in ips table.
                $sql_in = "insert into ips (id,userip) values ($id,'$ip')";
                mysql_query( $sql_in);
                //echo "&lt;script&gt;alert('Thanks for the vote');&lt;/script&gt;";

                echo json_encode($aResponse);
                echo '&lt;div class="exemple2" data="3_'.$id.'"&gt;&lt;/div&gt;';
            }
            else
            {
                $aResponse['error'] = true;
                $aResponse['message'] = 'You have already voted.';

                // ONLY FOR THE DEMO, YOU CAN REMOVE THE CODE UNDER
                    $aResponse['server'] = '&lt;strong&gt;ERROR :&lt;/strong&gt; Some error occured while registering your vote!';
                // END ONLY FOR DEMO


                echo json_encode($aResponse);
            }
        }
        else
        {
            $aResponse['error'] = true;
            $aResponse['message'] = '"action" post data not equal to \'rating\'';

            // ONLY FOR THE DEMO, YOU CAN REMOVE THE CODE UNDER
                $aResponse['server'] = '&lt;strong&gt;ERROR :&lt;/strong&gt; "action" post data not equal to \'rating\'';
            // END ONLY FOR DEMO


            echo json_encode($aResponse);
        }
    }
    else
    {
        $aResponse['error'] = true;
        $aResponse['message'] = '$_POST[\'action\'] not found';

        // ONLY FOR THE DEMO, YOU CAN REMOVE THE CODE UNDER
            $aResponse['server'] = '&lt;strong&gt;ERROR :&lt;/strong&gt; $_POST[\'action\'] not found';
        // END ONLY FOR DEMO


        echo json_encode($aResponse);
    }
</code></pre>
