How define a variable to display an Image

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
guycrossley
Forum Newbie
Posts: 9
Joined: Mon May 12, 2003 8:46 pm

How define a variable to display an Image

Post by guycrossley »

Hello,

I want to display an image, who's location is stored in a string. For Example:

$temp = "Images/UserIcons/Brettsface.png";

But, when i try

<img src= $temp width="100" height="100">

I dont get anything... What have i done wrong?

--Guy

(PS- However, this works <img src= "Images/UserIcons/Brettsface.png" width="100" height="100"> )
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

Code: Select all

<?php
$temp = "Images/UserIcons/Brettsface.png"; 
echo '<img src= "'.$temp.'" width="100" height="100">';  //check de simple quotes and the double quotes around $temp
?>
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Post by Czar »

you can also leave the php block and do it like;

Code: Select all

<?php 
$temp = "Images/UserIcons/Brettsface.png"; 
?>

<img src=<?php echo $temp; ?> width="100" height="100">
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

So many options... I usually do it like this:

Code: Select all

<?php
print "<img src="$temp" width="100" height="100">"; 
?>
guycrossley
Forum Newbie
Posts: 9
Joined: Mon May 12, 2003 8:46 pm

Post by guycrossley »

ah, thanks guys. The following code worked:

Code: Select all

<?php $temp = "Images/UserIcons/Brettsface.png";
   echo '<img src="'.$temp.'">'; 
?>
But this didn't, why?

Code: Select all

<?php $temp = $row_rsUsers&#1111;'USER_ICON']; 
    echo '<img src="'.$temp.'">'; 
?>
Is this a database issue, or is there a datatype mismatch or something?
guycrossley
Forum Newbie
Posts: 9
Joined: Mon May 12, 2003 8:46 pm

Post by guycrossley »

Ignore the last post,

$row_rsUsers['USER_ICON']

was returning an array because i didnt define the recordset correctly.

Thx for all your help guys! :D
Post Reply