我想使用 if 语句更改 td 颜色,但不知何故我的代码没有影响所有行
这是我的代码:
require_once("../model/materiel.class.php" . ""); $mt=new materiel(); $data=$mt->afficher_tous1(); echo '<table id="customers2" class="table datatable table-striped">'; echo "<thead> <tr> <th>Qte disponible</th> <th>Alert</th> </tr> </thead>"; echo "<tbody>"; foreach($data as $t){ echo "<tr>"; if ($t['qte_disponible_m'] == 0){ echo "<td bgcolor='red'>".$t['qte_disponible_m']."</td>"; }else if ($t['qte_disponible_m'] > $t['alert_m']){ echo "<td bgcolor='green'>".$t['qte_disponible_m']."</td>"; }else if ($t['qte_disponible_m'] == $t['alert_m']){ echo "<td bgcolor='yellow'>".$t['qte_disponible_m']."</td>"; } echo "<td>".$t['alert_m']."</td>"; echo "</tr>"; } echo "</tbody>"; echo"</table>";
- 我看到的问题如下截图:
If 语句就像跳转下一行
最佳答案
向 TD 添加一个具有 CSS background-color
属性(如果需要,可使用 !important
)的类,而不是 bgcolor。 bgcolor 被 table-striped
类覆盖。
关于php - 根据 MYSQL 值更改单元格颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38743144/