Forum Moderators: coopster
Anyways, I have urls similar to
blah.com/file.php?sort=1
Each number is suppose to have it's own content based on the sort number which I figured I'd accomplish by using an if statement. Well I did the code below and it doesn't work past sort=1. I thought it was right but may be missing the obvious and am hoping someone can take a look at it for me.
Here's the code....
$sort = $_GET['sort'];
if (empty($sort)) {
echo "empty";
}elseif($sort=1){
echo "1";
}elseif($sort=2){
echo "2";
}elseif($sort=3){
echo "3";
}
$sort = $_GET['sort'];if (empty($sort)) {
echo "empty";
}elseif($sort==1){
echo "1";
}elseif($sort==2){
echo "2";
}elseif($sort==3){
echo "3";
}
The = operator is to assign values to a variable
The == is to test for equality between values
You could also go for a switch statement to make it a little easier to read:
$sort = $_GET['sort'];
if (!empty($sort))
{
switch ($sort)
{
case 1:
echo '1';
break;
case 2:
echo '2';
break;
case 3:
echo '3';
break;
}
} else {
echo 'empty';
}