Converting numbers to visual rating (stars)?

php, rating-system

Solution

<?php
    for($x=1;$x<=$starNumber;$x++) {
        echo '<img src="path/to/star.png" />';
    }
    if (strpos($starNumber,'.')) {
        echo '<img src="path/to/half/star.png" />';
        $x++;
    }
    while ($x<=5) {
        echo '<img src="path/to/blank/star.png" />';
        $x++;
    }
?>

*Assuming you are using PHP

Problem

in my database ı have numbers `1`, `2`, `2.5`, `3`, `3.5`, `4`, `4.5` and `5` I want to convert these numbers to stars. I have a full star and a half star. How ı can do that after getting information from database? I have the rating tag on the database.

Original source