Page 1 of 1
display image as variable
Posted: Mon Jan 26, 2004 5:33 pm
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") {
$m1 = '$image; }
echo "$m1";
I keep getting a return of "$image" instead of the picture...
Posted: Mon Jan 26, 2004 5:42 pm
by niceguyeddie
Code: Select all
if ($d1 == "y") {
$m1 = $image;
}
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.
Posted: Mon Jan 26, 2004 5:57 pm
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") {
$m1 = '$image'; }
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 "${$marked}";
Since $m2 is marked y in the db it should return
<img src=\"../images/checkmark.gif\"> but it returns "$image"
Is that any clearer?
Posted: Mon Jan 26, 2004 8:02 pm
by ilovetoast
The code is functioning properly as written.
Code: Select all
if ($d1 == "y") {
$m1 = '$image';
}
Should print the string '$image'.
To print the image tag as you desire, use this instead....
Code: Select all
if ($d1 == "y") {
$m1 = "$image";
}
peace
two pieces of toast
Posted: Mon Jan 26, 2004 9:26 pm
by THEMADGEEK
Thanks Toast-Man that did it. I totally spaced the single quote string thing... obviously!
Thanks again!
Posted: Tue Jan 27, 2004 3:41 am
by twigletmac
You don't need any quotes around variable names by themselves at all:
should be used instead of:
Mac
Posted: Tue Jan 27, 2004 9:03 am
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
Posted: Tue Jan 27, 2004 5:39 pm
by THEMADGEEK
Thanks guys! Done...
Posted: Tue Jan 27, 2004 6:08 pm
by niceguyeddie
twigletmac wrote:You don't need any quotes around variable names by themselves at all:
should be used instead of:
Mac
heh, you illustrated the point better than I did originally I guess;)
Posted: Tue Jan 27, 2004 9:08 pm
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