Image using variable..problem

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
Rob
Forum Commoner
Posts: 33
Joined: Fri Oct 03, 2003 3:18 pm

Image using variable..problem

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

this is also possible (saves up two characters! (w00t) :P)

Code: Select all

<?php

echo "<td align='left' background={$_GET['cellheaderz']} bgcolor='#FF0000'><div align='center'><b>News</b></font></div></td>";

?>
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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>";

?>
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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? :D ), i only use double qoutes when needed...

why is the second one better? :?:
Post Reply