I am trying to create a visual representation of a user rating from 1 to 5 (including .5 values) in the form of stars and half-stars. I have already created the array of user ratings from the MySQL database, I have averaged those values to create an average user rating in the form of a number. What I would like to do is take this value..
$averageuserrating
And if that value is “1”, then return this code once
echo '<img src="images/star.png" class="ratingstar" />';
If $averageuserrating is 1.5, then this code will be returned
<img src="images/star.png" class="ratingstar" /><img src="images/halfstar.png" class="ratingstar" />
And so on… Is there a way to do this without 10 nested if statements?
It can be done by something like this:
On a side note, this is not the best way to display a rating system.