Reputation: 12858
At the moment i'm trying to use a stylesheet which i get through a if. but it doesn't do anything.
here is my code at the moment. the variable $stylesheet will be variable but while testing i've setted it to normal
<?php
$stylesheet = 'normal'
if ($stylesheet = 'small')
{
$style = './sitestyle/stylesheetsmall.css';
}
if ($stylesheet = 'big')
{
$style = './sitestyle/stylesheetbig.css';
}
else
{
$style = './sitestyle/stylesheet.css';
}
echo '<link rel="stylesheet" type="text/css" href="$style">';
?>
Thanks for your answers.
Upvotes: 1
Views: 4130
Reputation:
$stylesheet = 'normal'
if($stylesheet == 'small')
{
$style = './sitestyle/stylesheetsmall.css';
}
if($stylesheet == 'big')
{
$style = "./sitestyle/stylesheetbig.css";
}
else
{
$style = "./sitestyle/stylesheet.css";
}
echo '<link rel="stylesheet" type="text/css" href="' . $style . '">';
one equals is for assigning thing in php == is for if it is equal to and === is for if it is exactly equal to
Upvotes: 1
Reputation: 12254
You could also forgo the switch/if entirely.
<link rel="stylesheet" type="text/css" href="./sitestyle/stylesheet<?echo $style;?>.css">
Just make sure $style
is only ever set to ""
, "big"
, or "small"
Upvotes: 0
Reputation: 13804
Ok, so as the others have said, =
is assignation, ==
is comparision.
But your problem could be simplified by using a switch
statement:
$stylesheet = 'normal';
switch($stylesheet) {
case 'small':
$style = './sitestyle/stylesheetsmall.css';
break;
case 'big':
$style = './sitestyle/stylesheetbig.css';
break;
default:
$style = './sitestyle/stylesheet.css';
break;
}
echo '<link rel="stylesheet" type="text/css" href="'.$style.'">';
Upvotes: 9
Reputation: 30394
Others have pointed out the problem with your if statements. You also have a problem with your echo statement. Variables will not be looked at within single quotes. You need to move the variable out of the quotes and concatenate, or change to double quotes and escape all your other double quotes. I prefer the first method:
echo '<link rel="stylesheet" type="text/css" href="' . $style . '">';
Upvotes: 3
Reputation: 4218
you can use switch for this
switch ($size) { case 'small': # small css code... break; case 'big': # big css code... break; default: # default stylesheet code... break; }
Upvotes: 1
Reputation: 120644
You're using PHP's assignment operator instead of the equals operator for your comparisons:
if ($stylesheet = 'big')
That code actually assigns the value 'big' to $stylesheet
and the result of the assignment is then evaluated by the if
as a boolean (this would be true in PHP).
You're going to want to change the =
to ==
so that the expression is evaluated directly as a boolean instead of evaluating the result of the assignment:
if ($stylesheet == 'big')
Upvotes: 2
Reputation: 14618
If you want to check if a value is equal to another, use double equal sign ==
$stylesheet == 'small'
Upvotes: 0
Reputation: 41509
When comparing things, use ==
in stead of =
.
$a=0; if( $a = 1 ) { echo "1"; } else { echo "not 1"; }
The if( $a = 1 )
will use the return value of $a=1
as a condition, in this case the return value is $a
, which equals 1
.
Upvotes: 6