如何根据$ value更改文本颜色

时间:2016-11-25 11:22:44

标签: php html

我想根据$更改$value的颜色:如果低于10%则为红色,否则为黑色。给我重新制作的部分代码看起来像这样。

<td style="font-weight: bold; color: black;">'.round(100 * ($data[$tabele[$i]][$keys[$tabele[$i]][0]] + $data[$tabele[$i]]["RESERVED"] + $data[$tabele[$i]]["BIZ_AVAILABLE"]) / ArraySum($data[$tabele[$i]]) ,2).'%</td>

2 个答案:

答案 0 :(得分:0)

将计算存储在变量中,然后在样式中添加条件,以根据变量的值更改颜色。 (例如:

<?php $value = round(100 * ($data[$tabele[$i]][$keys[$tabele[$i]][0]] + $data[$tabele[$i]]["RESERVED"] + $data[$tabele[$i]]["BIZ_AVAILABLE"]) / ArraySum($data[$tabele[$i]]) ,2)); ?>

<td style="font-weight: bold; color: <?php if($value<10):?>red<?php else:?>black<?php endif;?>;"><?php echo $value?>%</td>

答案 1 :(得分:0)

    select 
X.VENDEDOR AS VENDEDOR,
X.VENDNM AS VENDNM,
X.NO AS NO,
X.nome AS nome,
isnull(sum(x.qtt_1),0) as Qtt_1,
isnull(sum(x.qtt_2),0) as Qtt_2,
#2# as Data1,
#3# as Data2,
#4# as Data3,
#5# as Data4,
(SELECT DESIGN FROM ST WHERE ST.forref ='*br1000*') AS ARTIGO,

(select isnull(sum(pn.qtt),0) from pn where pn.vendedor in (1,2,3,4,5,6,7,8,9) and (pn.fdata BETWEEN #2# AND #3#) and pn.usr1 not like '%'+'Portes'+'%') as Total1,

(select isnull(sum(pn.qtt),0) from pn where pn.vendedor in (1,2,3,4,5,6,7,8,9) and (pn.fdata BETWEEN #4# AND #5#) and pn.usr1 not like '%'+'Portes'+'%') as Total2,

((select isnull(sum(pn.qtt),0) from pn where pn.vendnm like x.vendnm and (pn.fdata BETWEEN #4# AND #5#) and pn.usr1 not like '%'+'Portes'+'%' )-(select isnull(sum(pn.qtt),0) from pn where pn.vendnm like x.vendnm and (pn.fdata BETWEEN #2# AND #3#) and pn.usr1 not like '%'+'Portes'+'%')) as Dif_Total_Vend,

isnull(
round((((select sum(pn.qtt) from pn where pn.vendedor in (1,2,3,4,5,6,7,8,9) and (pn.fdata BETWEEN #4# AND #5#) and pn.usr1 not like '%'+'Portes'+'%')
-
(select sum(pn.qtt) from pn where pn.vendedor in (1,2,3,4,5,6,7,8,9) and (pn.fdata BETWEEN #2# AND #3#) and pn.usr1 not like '%'+'Portes'+'%'))/
(select sum(pn.qtt) from pn where pn.vendedor in (1,2,3,4,5,6,7,8,9) and (pn.fdata BETWEEN #2# AND #3#) and pn.usr1 not like '%'+'Portes'+'%'))*100,2),0) as Perc_Dif,

isnull(
round((((select sum(pn.qtt) from pn where pn.vendnm like x.vendnm and (pn.fdata BETWEEN #4# AND #5#) and pn.usr1 not like '%'+'Portes'+'%')
-
(select sum(pn.qtt) from pn where pn.vendnm like x.vendnm and (pn.fdata BETWEEN #2# AND #3#) and pn.usr1 not like '%'+'Portes'+'%'))/
(select sum(pn.qtt) from pn where pn.vendnm like x.vendnm and (pn.fdata BETWEEN #2# AND #3#) and pn.usr1 not like '%'+'Portes'+'%'))*100,2),0) as Perc_Dif_Vend

from
(
select
pn.vendedor as Vendedor,
pn.vendnm as Vendnm,
pn.no as No,
(select nome from cl where cl.no=pn.no) as nome,
pn.qtt as Qtt_1,
0 as Qtt_2
from pn
where (pn.fdata BETWEEN #2# AND #3#) 

union all

select
pn.vendedor as Vendedor,
pn.vendnm as Vendnm,
pn.no as No,
(select nome from cl where cl.no=pn.no) as nome,
0 as Qtt_1,
pn.qtt as Qtt_2
from pn
where (pn.fdata BETWEEN #4# AND #5#) AND (pn.Vendedor '3' == pn.Vendedor '7')
)
x

group by x.no,x.nome, x.vendedor,x.vendnm
order by x.nome,x.vendedor