gpt4 book ai didi

php - tr bgcolor 取决于行值

转载 作者:行者123 更新时间:2023-11-29 06:15:47 25 4
gpt4 key购买 nike

我对 php 非常陌生,我有一个表格显示来 self 们支持门户的案例。案例的优先级设置为“高、中或低”,我希望每行的背景颜色根据该案例的优先级显示不同的颜色。例如,高 = 红色,低 = 白色,中 = 黄色。

下面是我的代码。我将如何实现这个?任何建议将不胜感激!

<?php
$priority = $val['priority'];
switch($priority)
{
case P3:
$prior_value = "Low";
break;
case P2:
$prior_value = "Medium";
break;
case P1:
$prior_value = "High";
}
?>

<tr height="30px">
<Td class="gridcontentredmid" style="width:65px;"><a href="showcase.php?case_id=<?=$val['id']?>">
<?=$val['case_number']?>
</a></Td>
<Td class="gridcontentmid" style="width:270px; text-align:left;">&nbsp;
<?=$val['name']?></Td>
<Td class="gridcontentmid" style="width:85px;" ><?=$val['status']?></Td>
<Td class="gridcontentmid"><?=$name?></Td>
<Td class="gridcontentmid" style="width:65px;"><?=$prior_value?></Td>
<Td class="gridcontentmidd" style="border-right:#000 1px solid"><?=$date_create?></Td>
</tr>

最佳答案

这是一个快速方法:

              $priority = $val['priority'];
switch($priority)
{
case P3:
$prior_value = "Low";
break;
case P2:
$prior_value = "Medium";
break;
case P1:
$prior_value = "High";
}
<b>$colors = array("High" => "red", "Medium" => "yellow", "Low" => "white");
$color = $colors[$prior_value];</b>


<tr <b>style="background-color: <?php echo $color; ?>"</b> height="30px">
<Td class="gridcontentredmid" style="width:65px;"><a href="showcase.php?case_id=<?=$val['id']?>">
<?=$val['case_number']?>
</a></Td>
<Td class="gridcontentmid" style="width:270px; text-align:left;">&nbsp;
<?=$val['name']?></Td>
<Td class="gridcontentmid" style="width:85px;" ><?=$val['status']?></Td>
<Td class="gridcontentmid"><?=$name?></Td>
<Td class="gridcontentmid" style="width:65px;"><?=$prior_value?></Td>
<Td class="gridcontentmidd" style="border-right:#000 1px solid"><?=$date_create?></Td>
</tr>

但是更好的方法是使用 CSS:

.priorityHigh {
background-color: red;
}

.priorityMedium {
background-color: yellow;
}

.priorityLow {
background-color: white;
}

              $priority = $val['priority'];
switch($priority)
{
case P3:
$prior_value = "Low";
break;
case P2:
$prior_value = "Medium";
break;
case P1:
$prior_value = "High";
}


<tr <b>class="priority<?php echo $prior_value; ?>"</b> height="30px">
<Td class="gridcontentredmid" style="width:65px;"><a href="showcase.php?case_id=<?=$val['id']?>">
<?=$val['case_number']?>
</a></Td>
<Td class="gridcontentmid" style="width:270px; text-align:left;">&nbsp;
<?=$val['name']?></Td>
<Td class="gridcontentmid" style="width:85px;" ><?=$val['status']?></Td>
<Td class="gridcontentmid"><?=$name?></Td>
<Td class="gridcontentmid" style="width:65px;"><?=$prior_value?></Td>
<Td class="gridcontentmidd" style="border-right:#000 1px solid"><?=$date_create?></Td>
</tr>

关于php - tr bgcolor 取决于行值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6618472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com