我试图动态地改变 TD 背景颜色,但这让我发疯,因为我真的不知道如何修复代码。
这是我的代码:
<td data-column="% Over 0.5 SH" style="background-color: <?php echo $backgroundColorOver05SH; ?>"> <?php if (($row['TotalMatch']) > 9){ $percover05sh = $row['OK_05sh'] / $row['TotalMatch'] * 100; echo sprintf("%.2f", $percover05sh); if ($percover05sh > 80){ $backgroundColorOver05SH = "green"; } elseif ($percover05sh >= 70 and $percover05sh <= 79.99 ){ $backgroundColorOver05SH = "yellow"; } else { $backgroundColorOver05SH = "red"; }
我认为我的方向是正确的,但我找不到正确的解决方案。 请问有什么建议吗?谢谢!
编辑:此代码现在可以运行了!这是我的完整代码:
<?php if (($row['TotalMatch']) > 9){ $percover05sh = $row['OK_05sh'] / $row['TotalMatch'] * 100; if ($percover05sh >= 80){ $backgroundColorOver05SH = "green"; } elseif ($percover05sh >= 70 && $percover05sh < 80 ){ $backgroundColorOver05SH = "yellow"; } else { $backgroundColorOver05SH = "red"; } }else{ echo 'No Bet'; } ?> <td data-column="% Over 0.5 SH" style="background-color: <?php echo $backgroundColorOver05SH;?>;"> <?php echo sprintf("%.2f", $percover05sh); ?> </td>
P粉9086436112024-04-01 00:23:43
除了更改代码中的顺序(如问题注释中所写)之外,我还会在 style 属性中由 PHP 回显的背景颜色值后面添加一个分号,即
回复0P粉9389363042024-04-01 00:13:34
所以首先:
9){ $percover05sh = $row['OK_05sh'] / $row['TotalMatch'] * 100; echo sprintf("%.2f", $percover05sh); if ($percover05sh > 80){ $backgroundColorOver05SH = "green"; } elseif ($percover05sh >= 70 && $percover05sh < 80 ){ $backgroundColorOver05SH = "yellow"; } else { $backgroundColorOver05SH = "red"; } ?>9){ */ } ?> 如果颜色没有改变,可能是由不同的 CSS 规则或脚本设置的?
回复0取消