Greater, less or equal to a value

Im trying to show different colours depending on the two values.

First of all if the values are equal then show green which works fine
        <?php if (miletofurlong($pasthorse['distance']) == $todaysdistance)
    {
    $Horsedist = "<b><span style='color:#ff4500 '>". miletofurlong($pasthorse['distance'])."f</span></b>";
    } ?>

Open in new window


now what im trying to do is if miletofurlong($pasthorse['distance']) is not equal to but is still between ($todaysdistance + 1) and ($todaysdistance + 1) then highlight it blue.

i have ran the following code but it seems to highlight everything and im unsure why


   
if (miletofurlong($pasthorse['distance']) == $todaysdistance)
    {
    $Horsedist = "<b><span style='color:#ff4500 '>". miletofurlong($pasthorse['distance'])."f</span></b>";
    }
    elseif (miletofurlong($pasthorse['distance']) !== $todaysdistance and miletofurlong($pasthorse['distance']) <= ($todaysdistance + 1) or miletofurlong($pasthorse['distance']) !== $todaysdistance and miletofurlong($pasthorse['distance']) >= ($todaysdistance - 1)  )
    {
    $Horsedist = "<b><span style='color:blue'>". miletofurlong($pasthorse['distance'])."f</span></b>". ($todaysdistance + 1). "and" . ($todaysdistance - 1);
    }
    else
    {
    $Horsedist = miletofurlong($pasthorse['distance'])."f" ;
    }

Open in new window

runnerjp2005Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Firstly, take your miletofurlong call outside of the if statement and set it to a variable
Secondly your elseif was not working because you were not bracketing your AND / OR bits - although in the solution below these have been removed

// Take this outside of the if statements
$mtfl = miletofurlong($pasthorse['distance']);

if ($mtfl == $todaysdistance)
{
  $Horsedist = "<b><span style='color:#ff4500 '>". $mtfl."f</span></b>";
}

elseif (($mtfl >= $todaysdistance - 1) && ($mtfl <= $todaysdistance - 1))
{
// You don't need to check for equality here - if you get here it is because
// the values are not equal
  $Horsedist = "<b><span style='color:blue'>". $mtfl."f</span></b>". ($todaysdistance + 1). "and" . ($todaysdistance - 1);
}
else
{
  $Horsedist = $mtfl."f" ;
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.