|
Author |
Message |
GunstarHero
Junior WebHelper
Joined: 15 Apr 2003
Posts: 35
|
Posted:
Sat Apr 26, 2003 8:19 pm (20 years, 12 months ago) |
|
Hi,
I'm using PHP/MySql. I have a rating system on my review page where each category is rated out of 10. Film, video, audio, extras and overall.
Instead of echoing the rating, I now want to convert it into a graphic. For example '1' represents '1' star etc.
I thought of evaluating the record using if/else to display graphics, but for 5 categories each with a possible 10 stars, it could be big!!
Is there an elegant way of doing this? Any pointers are much appreciated!
Cheers!
Anil |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sat Apr 26, 2003 9:29 pm (20 years, 12 months ago) |
|
Maybe like this:
Code: | echo('<img src="images/ratings/'.$rating.'.gif" />'); |
|
________________________________
|
|
|
|
GunstarHero
Junior WebHelper
Joined: 15 Apr 2003
Posts: 35
|
Posted:
Sat Apr 26, 2003 9:52 pm (20 years, 12 months ago) |
|
Hmmm, not sure. I have the existing code:
Code: | <?php echo $row_R['ratingfilm']; ?> |
which echoes the rating from the dbase. For example: 8
I want to turn it into a graphic. So '8' stars should be in it's place. If it was 1, then '1' star.
Wouldn't I need to evaluate the rating first, and then fetch a graphic to represent it? I would think there are 10 graphic images going from 1 star to 10 stars.
Code: | if ($row_R['ratingfilm'] == 1)
<img src="assets/images/1star.gif">
else do this instead |
This is what I think, but then I'm not sure how to code it. I'm sure there must be a good way to do it!
Anil |
|
|
|
|
drathbun
WebHelper
Joined: 01 Mar 2003
Posts: 69
Location: Texas
|
Posted:
Sat Apr 26, 2003 10:21 pm (20 years, 12 months ago) |
|
GunstarHero wrote: | Code: | if ($row_R['ratingfilm'] == 1)
<img src="assets/images/1star.gif">
else do this instead |
|
Here's an easy way. Create your graphics and name them 1star.gif, 2star.gif, ..., 10star.gif. Next, try this:
Code: | echo "<img src=" . $row_R['ratingfilm'] . $"star.gif" />" |
That will add the rating number to the beginning of your file name, resulting in your reference to the proper graphic. Make sense?
Dave |
________________________________ Dave
Photography Site :: Query Tools Forum :: Weekend Fun |
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Sat Apr 26, 2003 10:23 pm (20 years, 12 months ago) |
|
Code: | for($i = 0; $i < $row_R['ratingfilm']; ++$i)
print '<img src="assets/images/1star.gif">';
|
that should print the image tag the same number of times as the value of the rating...so you will get the star image five times for a rating of five. |
________________________________ It's turtles all the way down... |
|
|
|
GunstarHero
Junior WebHelper
Joined: 15 Apr 2003
Posts: 35
|
Posted:
Sat Apr 26, 2003 11:00 pm (20 years, 12 months ago) |
|
cheers all!
It's painfully obvious that I wonder why I didn't see it! D'oh!
I'm off to sleep now, I'll deal with it in the morning.
/me kicks himself before he goes to sleep...
Anil |
|
|
|
|
|
|
You cannot post new topics in this forum. You cannot reply to topics in this forum. You cannot edit your posts in this forum. You cannot delete your posts in this forum. You cannot vote in polls in this forum.
|
Page generation time: 0.233039 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme
| |