我试图根据这两个值显示不同的颜色。
首先,如果值相等,则显示绿色,工作正常
<?php if (miletofurlong($pasthorse['distance']) == $todaysdistance)
{
$Horsedist = "<b><span style='color:#ff4500 '>". miletofurlong($pasthorse['distance'])."f</span></b>";
} ?>
现在我要做的是,如果miletofurlong($pasthorse['distance'])
不等于但仍然在($ todaysdistance + 1)和($ todaysdistance + 1)之间,则将其突出显示为蓝色。
我运行了以下代码,但似乎突出了所有内容,我不确定为什么
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" ;
}
答案 0 :(得分:2)
你缺少括号,你的if情况有点乱。让我们首先使用变量并在里面声明你的$ pasthorse。
$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" ;
在那里,它应该更好地工作,并且更具可读性。