Forum Moderators: open
<?php
$votes = mysql_query("SELECT rat_rating FROM fs_nb_ratings WHERE rat_ID = 1");
$votesnr = 0;
$totalvotes = 0;
while($vote = mysql_fetch_array($votes)){
$votesnr ;
$totalvotes = $vote['rat_rating'];
}
if($votesnr == 0){
$rating = 0;
}
else {
$rating = $totalvotes/$votesnr;
}
$roundedrating = floor($rating) + round($rating - floor($rating)) / 2 ;
?>
<div class="star-rating" id="rating1result<?php echo $roundedrating; ?>" style="background-position:0 -<?php echo $roundedrating * 32; ?>px;">
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
<div class="star"></div>
</div>
<div class="result">
<span style="color:green"><?php echo round($rating,2); ?></span> (<?php echo $votesnr; ?>)
</div>
<script type="text/javascript">
$(function(){
$('.star').mouseover(function (){
var star = $(this).index()+1;
var x =(32 * star);
$(this).parent().css('backgroundPosition','0% ' +(-x)+ 'px');
});
$('.star-rating').mouseout(function (){
var originalresult = $(this).attr('id').split('result')[1];
var y =(32 * originalresult);
$(this).css('background-position','0%' +(-y)+ 'px');
});
});
$('.star').click(function (){
var id = $(this).parent().attr('id').split('rating')[1];
var vote = $(this).index() -1;
$.ajax({
type: "POST",
url:"save-vote.php",
data: 'id='+ id + '&vote='+ vote
});
$(this).parent().removeAttr("id");
$(this).parent().html(" ");
});
</script>
$id = intval($_POST['id']);
$vote = intval($_POST['vote']);
mysql_query("INSERT INTO fs_nb_ratings (rat_ID, rat_rating) VALUES(" . $id . "," . $vote . ")") or die(mysql_error());
Cannot call method 'split'
$('.star').click(function (){
var id = $(this).parent().attr('id').split('rating')[1];
var vote = $(this).index() -1; to +1