Click to See Complete Forum and Search --> : basic if statement?


k0r54
12-23-2004, 02:12 AM
Hi, I have posted something similar before but for some reason the same principle isn't working.


if ($searchtype == "animations" && $searchtype == "games" && $searchtype == "picturemsg") {
$extras = "extras/";
}



I am just trying to say is $searchtype = animations or games or picturemsg then $extras = "extras/"


Any ideas i have also only used a single = but that doesn't work either.

Can somebody please explain that to me aswell.

Thanks
k0r54

BuezaWebDev
12-23-2004, 03:13 AM
Originally posted by k0r54
Hi, I have posted something similar before but for some reason the same principle isn't working.


if ($searchtype == "animations" && $searchtype == "games" && $searchtype == "picturemsg") {
$extras = "extras/";
}



I am just trying to say is $searchtype = animations or games or picturemsg then $extras = "extras/"


Any ideas i have also only used a single = but that doesn't work either.

Can somebody please explain that to me aswell.

Thanks
k0r54



if (($searchtype == "animations") && ($searchtype == "games") && ($searchtype == "picturemsg")) {
$extras = "extras/";
}



Try that--It's always good to encapsulate your conditions.

k0r54
12-23-2004, 03:57 AM
Hi,

That doesn't work either but they do when when there is just one of them and not all 3 ??

dreamcatcher
12-23-2004, 04:54 AM
&& is the AND operator which means all the statements have to be true to echo your variable.

Try this:


if (($searchtype == "animations") || ($searchtype == "games") || ($searchtype == "picturemsg")) {
$extras = "extras/";
}

k0r54
12-23-2004, 05:19 AM
Hi, again sorry its still dont work??

Da Warriah
12-23-2004, 09:17 AM
How are you setting the $searchtype variable? It's likely not being set properly, because dreamcatcher's code should work fine...

ShrineDesigns
12-23-2004, 02:05 PM
try this:if(isset($searchtype) && ($searchtype == "animations" || $searchtype == "games" || $searchtype == "picturemsg"))
{
$extras = "extras/";
}

moondance
12-23-2004, 05:03 PM
If all you are looking for is the presence of a value, maybe a less chunky way of doing it would be to use an array eg:


if(isset($searchtype))
{
$myArray = array('animations','games','picturemsg');

if(in_array($searchtype, $myArray))
{
$extras = "extras\";
}
}

sydelct
12-27-2004, 11:37 AM
try doing an echo $searchtype and see if $searchtype has a value.

I am assuming that $searchtype is passed via post or get and if that's the case then you might have register_globals set to off and because of that, $searchtype is not being set.

i use "echo" a lot of times when debugging.