Page 1 of 1
why won't this work?
Posted: Thu Nov 26, 2009 2:02 pm
by Todlerone
Hello everyone and again TY in advance for any help/suggestions. This code won't work for me, is the syntax incorrect? If I echo the variables before the if loop there are values stored in them.
Code: Select all
$dothis = "($Visitor == $team) || ($Home == $team)";
if ($dothis){
...
}
TY again
Re: why won't this work?
Posted: Thu Nov 26, 2009 2:11 pm
by pickle
Strings evaluate to false if they are equivalent to boolean false (pretty much just the string "0"). Anything else evaluates to TRUE. Your string, though it contains characters a human would view as boolean conditions, is just treated like any other string & will always return TRUE
Re: why won't this work?
Posted: Thu Nov 26, 2009 2:17 pm
by Todlerone
What can I do to get around this? I want to enter the loop if either the $Home or $Visitor is equal to the $team variable.
TY Pickle
Re: why won't this work?
Posted: Thu Nov 26, 2009 2:19 pm
by iankent
Code: Select all
$dothis = ($Visitor == $team) || ($Home == $team) ? true : false;
if ($dothis){
...
}
if $Visitor == $team or if $Home == $team then $dothis becomes true, otherwise it becomes false.
Re: why won't this work?
Posted: Thu Nov 26, 2009 2:19 pm
by pickle
Don't put it in a string
Code: Select all
if($Visitor == $team || $Home == $team)
Re: why won't this work?
Posted: Thu Nov 26, 2009 2:27 pm
by Todlerone
The problem is the $dothis varies depending on the search result selected in a switch loop.
TY
Re: why won't this work?
Posted: Thu Nov 26, 2009 2:32 pm
by Monotoko
what are you after doing with the script?
You could do something like this:
Code: Select all
<?php
if ($Visitor==$team) // If the visitior is the team...
{
//do some code if the visitor is the team..
}
elseif ($Home == $team) //or if the home is the team..
{
//do some code here if the home is the team...
}
?>
Re: why won't this work?
Posted: Thu Nov 26, 2009 2:38 pm
by Todlerone
I'm just trying to reuse the same code. If either home or visitor is true do the code otherwise loop to next element in array. I didn't think I would run into a problem with the $dothis"..." assignment. for the If loop.