Reputation: 769
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>";
} ?>
Now what I'm 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 I'm 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" ;
}
Upvotes: 2
Views: 70
Reputation: 2085
You're missing parenthesis, and your if case is a bit messy. Let's first use a variable and declare your $pasthorse inside.
$distance = miletofurlong($ pasthorse['distance']);
if ($distance == $todaysdistance)
$Horsedist = "<b><span style='color:#ff4500 '>". $distance ."f</span></b>";
else if ($distance <= ($todaysdistance + 1) and $distance >= ($todaysdistance - 1) )
$Horsedist = "<b><span style='color:blue'>". $distance . "f</span></b>" ($todaysdistance + 1). "and" . ($todaysdistance - 1);
else
$Horsedist = $distance ."f" ;
There, it should work way better, and it's more readable.
Upvotes: 2