> echo "<td bgcolor="$bgcolor"><font face=Verdana
size=1><b>$cd_id</b></font></td>";
Strings work differently when the outer quotes are double or single quotes.
Inside double quotes variables will be converted into their values. Inside
single they will not.
So:
$var = 'Hello World';
echo "$var<br>\n";
will result in
Hello World<br><newline>
and:
$var = 'Hello World';
echo '$var<br>\n';
will result in
$var<br>\n //actual two characters '\' and 'n' and not newline.
Inside double or single quotes, you can use the other quote:
$var = 'Hello "World"';
echo "$var<br>\n";
Hello "World"<br><newline>
$var = "Hello 'World'";
echo "$var<br>\n";
Hello 'World'<br><newline>
Your trouble is that you're using double quotes inside a double quoted
string and the second double quote that php encounters will terminate the
string. The next thing encountered is your variable $bgcolor, but that
syntax isn't correct. php sees your string as three pieces:
1. "<td bgcolor="
2. $bgcolor
3. "><font face=Verdana size=1><b>$cd_id</b></font></td>";
So you could either convert the double quotes inside the string into single
quotes:
echo "<td bgcolor='$bgcolor'><font face=Verdana
size=1><b>$cd_id</b></font></td>";
or escape the double quotes like this:
echo "<td bgcolor=\"$bgcolor\"><font face=Verdana
size=1><b>$cd_id</b></font></td>";
or you could concatenate the three pieces:
echo "<td bgcolor=" . $bgcolor ."><font face=Verdana
size=1><b>$cd_id</b></font></td>";
I personally like all of the tag values double quoted so I'd
echo "<td bgcolor=\"$bgcolor"\><font face=\"Verdana\"
size=\"1\"><b>$cd_id</b></font></td>";
When php parses the outside double quoted string, it has to do extra work to
convert variables. I generally use single quotes unless there's a variable
or special char to convert (like newline). It doesn't really matter though,
it's fast anyway.
If your using arrays inside a double quoted string, you need to help php out
and use special coding. This code won't work:
$arr = array('fish' =>'Tuna','reptile' => 'Snake','rodent' => 'mouse');
echo "$arr['fish']<br>\n";
This will work:
$arr = array('fish' =>'Tuna','reptile' => 'Snake','rodent' => 'mouse');
echo "{$arr['fish']}<br>\n"; // note the curly braces around the array
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php