You can then style that with CSS, so to display background images according to stars. If you convert the <b> tags to <a> tags it's probably more semantic.
Consider using sprites. Start with a graphic that contains a row of stars for each possible rating, and then compute the background offset by multiplying the height of each half-star graphic times the number of half-stars in the rating.
E.g.:
<?php
$offset =
($rating / .5) // number of half-stars in $rating
* 15; // height of each sprite in stars.png
?>
<div style="background-image:url("stars.png");background-position:0 <?php echo $offset; ?>px;"></div>
*Assuming you are using PHP
You can do that with PHP, HTML and CSS:
You can then style that with CSS, so to display background images according to stars. If you convert the
<b>
tags to<a>
tags it's probably more semantic.Here, this adds stars
echo '*';
and halfs if neededecho '+';
Change
'*'
and'+'
for example to<img src="star.gif" />
and<img src="halfstar.gif" />
When I have done this in the past, I used one image of 5 empty stars underneath one image of 5 filled stars. I then did something like
This way you can display ratings of like 3.2978 etc.
Consider using sprites. Start with a graphic that contains a row of stars for each possible rating, and then compute the background offset by multiplying the height of each half-star graphic times the number of half-stars in the rating.
E.g.:
Combined with a little bit of Javascript, you can implement a fully-featured ratings widget.