display image as variable

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
THEMADGEEK
Forum Newbie
Posts: 21
Joined: Thu Oct 30, 2003 6:04 pm

display image as variable

Post by THEMADGEEK »

I am trying to display an image when a certain value = True but I am having no luck it displays the $variable_name not the image. What am I doing wrong?

Code: Select all

$image = "<img src="../images/checkmark.gif">";

if ($d1 == "y") &#123;
$m1 = '$image; &#125;

echo "$m1";
I keep getting a return of "$image" instead of the picture...
niceguyeddie
Forum Newbie
Posts: 13
Joined: Fri Nov 28, 2003 7:12 am
Location: Westminster, MD

Post by niceguyeddie »

Code: Select all

if ($d1 == "y") &#123;
    $m1 = $image; 
&#125;
You have a stray single quote in that, making PHP ignor that $image is a var. Surprised there isn't a parse error to be honest with the way it is written.
THEMADGEEK
Forum Newbie
Posts: 21
Joined: Thu Oct 30, 2003 6:04 pm

Post by THEMADGEEK »

That's not it, that was a typo when I put it in the forum...

Let me go a little deeper...

This is supposed to place a checkmark (image) in a calendar day when that day has been selected in the database (all that is working properly).

So after I query the db I set the variable and do the if statement

Code: Select all

$image = "<img src="../images/checkmark.gif">"; 

if ($d1 == "y") &#123; 
$m1 = '$image'; &#125;
In my calendar script each day is returned as $i (again all works great) so I have to make the 1st or $d1 display this image if $d1 was equal to "y" in the database...

Code: Select all

$marked = 'm'.$i; (this properly returns $m1, $m2 etc...)
echo "$&#123;$marked&#125;";
Since $m2 is marked y in the db it should return
<img src=\"../images/checkmark.gif\"> but it returns "$image"

Is that any clearer?
ilovetoast
Forum Contributor
Posts: 142
Joined: Thu Jan 15, 2004 7:34 pm

Post by ilovetoast »

The code is functioning properly as written.

Code: Select all

if ($d1 == "y") &#123;
    $m1 = '$image';
&#125;
Should print the string '$image'.

To print the image tag as you desire, use this instead....

Code: Select all

if ($d1 == "y") &#123;
    $m1 = "$image";
&#125;
peace

two pieces of toast
THEMADGEEK
Forum Newbie
Posts: 21
Joined: Thu Oct 30, 2003 6:04 pm

Post by THEMADGEEK »

Thanks Toast-Man that did it. I totally spaced the single quote string thing... obviously!

Thanks again!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You don't need any quotes around variable names by themselves at all:

Code: Select all

$m1 = $image;
should be used instead of:

Code: Select all

$m1 = "$image";
Mac
ilovetoast
Forum Contributor
Posts: 142
Joined: Thu Jan 15, 2004 7:34 pm

Post by ilovetoast »

Thanks for correcting that, twigletmac. I was so focused on the variable variable names, I made that ugly code booboo.

peace

i dropped my toast
THEMADGEEK
Forum Newbie
Posts: 21
Joined: Thu Oct 30, 2003 6:04 pm

Post by THEMADGEEK »

Thanks guys! Done...
niceguyeddie
Forum Newbie
Posts: 13
Joined: Fri Nov 28, 2003 7:12 am
Location: Westminster, MD

Post by niceguyeddie »

twigletmac wrote:You don't need any quotes around variable names by themselves at all:

Code: Select all

$m1 = $image;
should be used instead of:

Code: Select all

$m1 = "$image";
Mac
heh, you illustrated the point better than I did originally I guess;)
User avatar
Meteo
Forum Newbie
Posts: 24
Joined: Sun Jan 18, 2004 10:19 am
Contact:

Post by Meteo »

just a suggestion

Code: Select all

$image = "<img src="../images/checkmark.gif">";

// that is a little confusing, this is a little easier...

$image = '<img src="../images/checkmark.gif">';
it's just a little better for looking at, I think. it's not that important, just thought I'd suggest it
Post Reply