Forum Moderators: coopster
I'm trying to define several different styles in my web page based on one variable in the query string. So if I have www.mysite.com/index.php?style=1 then I want table cells to be a certain color, links to be a certain color, etc. Obviously style=2 would be a different color scheme.
I have the following code but it doesn't seem to work.
<?php$style = $_GET['style'];
if ( $style == 1 ) {
$border = 336699;
$bg = FFFFFF;
$links = 0000FF;
$url = 008000;
$text = 000000;
$footer = FFFFFF;
}
if ( $style == 2 ) {
$border = 000000;
$bg = F0F0F0;
$links = 0000FF;
$url = 008000;
$text = 000000;
$footer = FFFFFF;
}
?>
It produces "Parse error: parse error, unexpected T_STRING in /home/drivenin/public_html/partners/style.php on line 12"
Can anyone help me with this? Please let me know if you need furhter info.
Thanks,
Dan
it's because you are missing your quotes
if ( $style == 1 ) {
$border = '336699';
$bg = 'FFFFFF';
$links = '0000FF';
$url = '008000';
$text = '000000';
$footer = 'FFFFFF';
}
if ( $style == 2 ) {
$border = '000000';
$bg = 'F0F0F0';
$links = '0000FF';
$url = '008000';
$text = '000000';
$footer = 'FFFFFF';
try that
Try:
$style = (int)$_GET['style'];
switch($style)
{
case 1:
$border = '#336699';
$bg = '#FFFFFF';
$links = '#0000FF';
$url = '#008000';
$text = '#000000';
$footer = '#FFFFFF';
break;
case 2:
$border = '#000000';
$bg = '#F0F0F0';
$links = '#0000FF';
$url = '#008000';
$text = '#000000';
$footer = '#FFFFFF';
break;
}
(I've also typecast the $_GET variable so it will only return an integer, and put your options into a switch statement, which will make it easier to read as you add more styles)
here you can find more info about switch [php.net]