Reputation: 715
I want to give the user to rate stars and also I want to update the database value after the user is rating it.
Here is my PHP code.
<?php foreach($genres as $genre){
$jsqla = mysql_query("select id,name,rate_score,rate_number,video_image from products where genre='$genre' limit 0,5");
while($jrowa = mysql_fetch_assoc($jsqla)){
if($jrowa['rate_number'] > 0){ $ratea = $jrowa['rate_score'] / $jrowa['rate_number']; }else{ $ratea = 0;
}
?>
Here is my HTML code.
<input class="rating form-control input-star-rate" value="<?php echo $ratea; ?>" data-min="0" data-max="5" data-step="0.3" data-size="xs" style="display: none; text-align: center;"/>
Upvotes: 0
Views: 2073
Reputation: 1574
simple rating using html/javascript
//HTML:
<form class="rating" method="post">
<input type="radio" id="star5" name="rating" value="5" onclick="postToController();" /><label for="star5" title="Super !!">5 stars</label>
<input type="radio" id="star4" name="rating" value="4" onclick="postToController();" /><label for="star4" title="Geil">4 stars</label>
<input type="radio" id="star3" name="rating" value="3" onclick="postToController();" /><label for="star3" title="Gut">3 stars</label>
<input type="radio" id="star2" name="rating" value="2" onclick="postToController();" /><label for="star2" title="So gut wie">2 stars</label>
<input type="radio" id="star1" name="rating" value="1" onclick="postToController();" /><label for="star1" title="Schlecht">1 star</label>
</form>
//Javascript:
function postToController() {
for (i = 0; i < document.getElementsByName('rating').length; i++) {
if(document.getElementsByName('rating')[i].checked == true) {
var ratingValue = document.getElementsByName('rating')[i].value;
break;
}
}
alert(ratingValue);
}
Here is good solution for rating system in php Link
Upvotes: 1