Tuesday, 15 September 2015

php - How to calculate star rating? -



php - How to calculate star rating? -

i have 1 product , want calculate 5 star rating on basic , dislike

for illustration product have

like = 200 // means 200 user product dislike =10 // means 10 user dislike particular product

here's simple php function:

<?php function calculatestarrating($likes, $dislikes){ $maxnumberofstars = 5; // define maximum number of stars possible. $totalrating = $likes + $dislikes; // calculate total number of ratings. $likepercentagestars = ($likes / $totalrating) * $maxnumberofstars; homecoming $likepercentagestars; } ?>

to phone call function:

<?php $likecount = 190; $dislikecount =10; $calculatedrating = calculatestarrating($likecount, $dislikecount); ?>

to utilize calculated value in javascript:

<script> var rating = <?php echo $calculatedrating; ?>; alert(rating); // testing purposes. </script>

these started.

php jquery rating

No comments:

Post a Comment