Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting numbers to visual rating (stars)? [closed]

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.

like image 767
salim basar Avatar asked Apr 20 '12 17:04

salim basar


1 Answers

<?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

like image 141
Wouter Rutgers Avatar answered Oct 27 '22 11:10

Wouter Rutgers