开发者

Display Star Rating without voting

I am a little stuck.

I have a Mysql database with items. Each item already has a corresponding rating (0-5).

Now, when I display the list of items, I want to convert the rating in stars. They may not be clickable.

But how can I display rating stars for each rating?

Li开发者_JS百科ke:

Item[1] Rating: 4 => display 4 stars
Item[2] Rating: 2 => display 2 stars
Item[3] Rating: 1 => display 1 star
and so on

I am calling the existing rating like this:

php echo $item['Item']['rating']


str_repeat():

print str_repeat('*', $item['Item']['rating']);


for ($i = 0; $i < $item['Item']['rating']; $i++) {
    echo '<img src="star.gif" />';
}


echo str_repeat('*', $item['Item']['rating']);

it will print * as many times as ratings..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜