2016-08-03 365 views
0

我想用if语句,但不知何故我的代码不影响所有行更改单元格颜色

  1. 这种改变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>"; 
    
  2. 的问题我已经看到下面的截图:

if语句就像是跳进下一行

Screenshot

+2

如果知道'$ t ['alert_m']'是否在您的测试中使用它将是有用的!它并没有显示在你的照片中。但那是你需要寻求解决这个问题的地方。在你的循环的每一次迭代中,它可能都是<<$ t ['qte_disponible_m']' – RiggsFolly

回答

1

与(如果需要与!important)的CSS background-color属性添加类的TD,而不是BGCOLOR。 bgcolor被table-striped类覆盖。

+0

谢谢你的信息 –