我有一个与mysql数据库连接的表。当tr中的每个单元都已满时,我需要更改颜色。您能建议我解决此问题的最佳方法吗?
<table class="table table-bordered">
<thead>
<tr>
<th class="text-center" style="width: 10%;"> Slika</th>
<th class="text-center" style="width: 10%;"> Ime producta </th>
<th class="text-center" style="width: 10%;"> Kategorija </th>
<th class="text-center" style="width: 10%;"> Zemun </th>
<th class="text-center" style="width: 10%;"> Balkanska </th>
<th class="text-center" style="width: 10%;"> Novi Sad </th>
<th class="text-center" style="width: 10%;"> Bulevar </th>
<th class="text-center" style="width: 10%;"> Piramida </th>
<th class="text-center" style="width: 10%;"> Datum dodavanja</th>
</tr>
</thead>
<tbody>
<?php foreach ($products as $product):?>
<tr>
<td> <?php echo remove_junk($product['image']); ?></td>
<td> <?php echo remove_junk($product['name']); ?></td>
<td> <?php echo remove_junk($product['categorie']); ?></td>
<td> <?php echo remove_junk($product['zemun']); ?></td>
<td> <?php echo remove_junk($product['balkanska']); ?></td>
<td> <?php echo remove_junk($product['novi_sad']); ?></td>
<td> <?php echo remove_junk($product['bulevar']); ?></td>
<td> <?php echo remove_junk($product['piramida']); ?></td>
<td> <?php echo read_date($product['date']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
答案 0 :(得分:1)
您可以为这样的行显示所有数据时创建一个CSS类名称...
PHP:
std::flush
HTML:
$showColor = "";
if(!empty($product['image']) && !empty($product['name']) &&
!empty($product['categorie']) && !empty($product['zemun']) &&
!empty($product['balkanska']) && !empty($product['novi_sad']) &&
!empty($product['bulevar']) && !empty($product['piramida']) &&
!empty($product['date'])) {
$showColor = "show_color";
}
CSS:
<tr class="<?php echo $showColor; ?>">
...
</tr>