Page 1 of 1
Image using variable..problem
Posted: Thu Apr 15, 2004 9:23 pm
by Rob
Hey, on my site I use a variable to set a table header image..it works on everything except my news script.
echo "<td align='left' background='$cellheaderz' bgcolor='#FF0000'><div align='center'><b>News</b></font></div></td>";
$cellheaderz is the image I want..its in URL form, so it should work but for some reason the variable is cleared. Any ideas?
Could it be because I have functions in my news script?
Posted: Thu Apr 15, 2004 9:41 pm
by John Cartwright
try this:
Code: Select all
<?
echo "<td align='left' background=".$_GET['cellheaderz']." bgcolor='#FF0000'><div align='center'><b>News</b></font></div></td>";
?
*edit* what do you mean the variable is cleared... to get the value of a variable in a URL you cannot simply echo the variable itself you have to use a $_GET for URL or $_POST from forms... or else you "think" the variable would of been cleared.
Posted: Fri Apr 16, 2004 3:17 am
by vigge89
this is also possible (saves up two characters! (w00t)

)
Code: Select all
<?php
echo "<td align='left' background={$_GET['cellheaderz']} bgcolor='#FF0000'><div align='center'><b>News</b></font></div></td>";
?>
Posted: Fri Apr 16, 2004 10:13 am
by JAM
vigge89 wrote:this is also possible (saves up two characters! (w00t) :P)
Well, that we can discuss, as you missed the issue about allways quoting values. Of course there are various of ways to to this, but...
Code: Select all
<?php
// last example
echo "<td align='left' background={$_GET['cellheaderz']} bgcolor='#FF0000'><div align='center'><b>News</b></font></div></td>";
// better
echo "<td align="left" background="{$_GET['cellheaderz']}" bgcolor="#FF0000"><div align="center"><b>News</b></font></div></td>";
?>
Posted: Fri Apr 16, 2004 3:23 pm
by vigge89
i always use the single qoutes, since i don't have to escape them (in most cases) while in double-qoute mode (nice name, huh?

), i only use double qoutes when needed...
why is the second one better?
