4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 converting numbers into graphics
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
GunstarHero
Junior WebHelper
Junior WebHelper


Joined: 15 Apr 2003
Posts: 35

PostPosted: Sat Apr 26, 2003 8:19 pm (14 years, 6 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by GunstarHeroSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sat Apr 26, 2003 9:29 pm (14 years, 6 months ago) Reply with QuoteBack to Top

Maybe like this: Question

Code:
echo('<img src="images/ratings/'.$rating.'.gif" />');

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
GunstarHero
Junior WebHelper
Junior WebHelper


Joined: 15 Apr 2003
Posts: 35

PostPosted: Sat Apr 26, 2003 9:52 pm (14 years, 6 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by GunstarHeroSend Personal Message
drathbun
WebHelper
WebHelper


Joined: 01 Mar 2003
Posts: 69
Location: Texas

PostPosted: Sat Apr 26, 2003 10:21 pm (14 years, 6 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by drathbunSend Personal MessageVisit Poster's Website
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Sat Apr 26, 2003 10:23 pm (14 years, 6 months ago) Reply with QuoteBack to Top

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...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
GunstarHero
Junior WebHelper
Junior WebHelper


Joined: 15 Apr 2003
Posts: 35

PostPosted: Sat Apr 26, 2003 11:00 pm (14 years, 6 months ago) Reply with QuoteBack to Top

cheers all!

It's painfully obvious that I wonder why I didn't see it! D'oh! Very Happy

I'm off to sleep now, I'll deal with it in the morning.

/me kicks himself before he goes to sleep...

Anil
OfflineView User's ProfileFind all posts by GunstarHeroSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




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.096104 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme