using images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dev2761
Forum Newbie
Posts: 16
Joined: Thu Oct 16, 2003 7:55 am
Contact:

using images

Post by dev2761 »

What I would like to do is display an image instead of a number in my page.
That is to say I have a little form which has a select box from 0 - 9.(there are other fields)
This puts the input into a MySQL db, I have also created 10 little gif images (yes, you got it they're stars, but this is not a poll or voting script) which I have placed in a directory of their own, this will not change.
And what I would like to do is instead of printing the number 2 is to put the 2star gif in its place.
I have looked everywhere and all I've found is poll or voting scripts which do net exactly help me, thanks in advance.
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

Code: Select all

<?php
if($number == 2) { print"<img src="images/2star.gif">"; }
?>
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

or better yet:

Code: Select all

<?php
print"<img src="images/{$number}star.gif">";
?>
User avatar
dev2761
Forum Newbie
Posts: 16
Joined: Thu Oct 16, 2003 7:55 am
Contact:

Post by dev2761 »

liljester u're the tops thank you very much!!!
I'm not much of a php programmer but what I'm trying to do is create a little form so that my son can add all his Yu-Gi-Oh cards and display them and as you know they have stars to denote how high they are!!!
Anyway thanks again
User avatar
dev2761
Forum Newbie
Posts: 16
Joined: Thu Oct 16, 2003 7:55 am
Contact:

Post by dev2761 »

Once again thank you for your help and I hope that you can still help me out.....
Now :

Code: Select all

<?php 
print"<img src="images/{$number}star.gif">"; 
?>
works for an image on the page but
how would I use that in a table as the background image ???
I have used both print and echo and they didn't seem to work but its most probably me and my bad syntax!!!!
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Code: Select all

<?php

echo <<< END
<table cellpadding="0" cellspacing="0" border="0" style="background:url({$number});">
<tr><td>
it's the background!!
</td></tr>
</table>
</table>
END;

?>
Hope that helps,

-Nay
User avatar
dev2761
Forum Newbie
Posts: 16
Joined: Thu Oct 16, 2003 7:55 am
Contact:

Post by dev2761 »

Thanks peeps for the good work, and like I said its most probably my real bad syntax and it was!!!
Post Reply