I've been trying to do add a couple of new features to my script all day for example, I want to be able to display the average rate and votes casted under my star rating images, like some thing in the example below.
**********
9.8/10 (1160 vote cast)
I've been trying everything and run into new problem after problem after problem. For instance now each new PHP function I have interferes with one another.
For instance my first PHP function getRating()
works correctly all by itself but it will not display correctly when using it with my second PHP function evaluateRatingText()
and my first PHP function messes up my second PHP function by displaying the average rating all wrong for example it actually displays the value twice.
So how can I make both of my PHP functions work correctly along with my JQuery function which displays my first php function getRating()
correctly so that my JQuery function can display both PHP functions accordingly? Can anyone help me out examples would be great?
Here is my PHP functions.
// function to retrieve
function getRating(){
$sql= "select * from vote";
$result=@mysql_query($sql);
$rs=@mysql_fetch_array($result);
// set width of star
$rating = (@round($rs['value'] / $rs['counter'],1)) * 10;
echo $rating;
}
// function to retrieve average rating and votes
function evaluateRatingText(){
$sql= "select * from vote";
$result=@mysql_query($sql);
$rs=@mysql_fetch_array($result);
$avg = (@round($rs['value'] / $rs['counter'],1)) * 10;
$votes = $rs['counter'];
echo $avg . "/10 (" . $votes . " votes cast)";
}
Here is the JQuery function.
// get current rating
getRating();
// get rating function
function getRating(){
$.ajax({
type: "GET",
url: "update.php",
data: "do=getrate",
cache: false,
async: false,
success: function(result) {
// apply star rating to element
$("#current-rating").css({ width: "" + result + "%" });
},
error: function(result) {
alert("some error occured, please try again later");
}
});
}
HTML Markup.
<ul class='star-rating'>
<li class="current-rating" id="current-rating"></li>
<li class="rating-text" id="rating-text"></li>
<span id="ratelinks">
<li><a href="javascript:void(0)" title="1 star out of 10" class="one-star">1</a></li>
<li><a href="javascript:void(0)" title="2 stars out of 10" class="two-stars">2</a></li>
<li><a href="javascript:void(0)" title="3 stars out of 10" class="three-stars">3</a></li>
<li><a href="javascript:void(0)" title="4 stars out of 10" class="four-stars">4</a></li>
<li><a href="javascript:void(0)" title="5 stars out of 10" class="five-stars">5</a></li>
<li><a href="javascript:void(0)" title="6 stars out of 10" class="six-star">6</a></li>
<li><a href="javascript:void(0)" title="7 stars out of 10" class="seven-stars">7</a></li>
<li><a href="javascript:void(0)" title="8 stars out of 10" class="eight-stars">8</a></li>
<li><a href="javascript:void(0)" title="9 stars out of 10" class="nine-stars">9</a></li>
<li><a href="javascript:void(0)" title="10 stars out of 10" class="ten-stars">10</a></li>
</span>
</ul>