gpt4 book ai didi

php - 如何给表 tr 上色?

转载 作者:太空宇宙 更新时间:2023-11-04 15:39:56 27 4
gpt4 key购买 nike

你好,我有一个表,其中包含一些字段,例如
enter image description here

这里我想为表格整行设置颜色..意味着如果 ASR 值是 75 到 100 应该得到一种颜色,50 到 75 应该得到另一种颜色,低于 50 应该得到另一种颜色。

这是我的php代码

<table width="75%" border="1">
<tr>
<td align="center">channel no</td>
<td align="center">IP</td>
<td align="center">Total calls</td>
<td align="center">Connected calls</td>
<td align="center">Disconnected calls</td>
<td align="center">Duration</td>
<td align="center">ASR</td>
<td align="center">ACD</td>

</tr>
<?php

while ($row = mysql_fetch_assoc($result)) {

//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr>

<td>".$row['channel']."&nbsp;</td>
<td>".$row['ip']."&nbsp;</td>
<td>".$row['totalcalls']."&nbsp;</td>";

if ($row['totalcalls']>1){
$sql1 = "SELECT count(duration) as count FROM gateways where duration=0 and ip='".$_POST['ip']."' and channel='".$row['channel']. "' and (connect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' or disconnect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' ) Group by channel";

$result1 = mysql_query($sql1, $link);
$norow=mysql_fetch_assoc($result1);
$attenedcalls=($row['totalcalls']-$norow['count']);
echo "<td>".$attenedcalls."&nbsp;</td>";
$disconnectedcalls=($row['totalcalls']-$attenedcalls);
echo "<td>".$disconnectedcalls."&nbsp;</td>";
echo " <td>".$row['tduration']."&nbsp;</td>";
echo "<td>".(($attenedcalls/$row['totalcalls'])*100)."</td>";
}else{

echo "<td>".$row['totalcalls']."</td>";

echo "<td>100</td>";

}

$minutes = gmdate("H:i:s", ($row['tduration']/$attenedcalls));
echo " <td>".$minutes."&nbsp;</td>
</tr>";
}
?>
</table>

提前致谢

最佳答案

你可以这样试试

<table width="75%" border="1">
<tr>
<td align="center">channel no</td>
<td align="center">IP</td>
<td align="center">Total calls</td>
<td align="center">Connected calls</td>
<td align="center">Disconnected calls</td>
<td align="center">Duration</td>
<td align="center">ASR</td>
<td align="center">ACD</td>

</tr>
<?php

while ($row = mysql_fetch_assoc($result)) {
$color = '';
if ($row['totalcalls']>1){
$sql1 = "SELECT count(duration) as count FROM gateways where duration=0 and ip='".$_POST['ip']."' and channel='".$row['channel']. "' and (connect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' or disconnect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' ) Group by channel";

$result1 = mysql_query($sql1, $link);
$norow=mysql_fetch_assoc($result1);
$attenedcalls=($row['totalcalls']-$norow['count']);
$asr = (($attenedcalls/$row['totalcalls'])*100);
if($asr >= 75 && $asr <=100 ){
$color = 'red';
}else if($asr >= 50 && $asr < 75){
$color = 'cyan';
}else if($asr < 50){
$color = 'blue';
}
}
//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr style='background-color : ".$color."'>

<td>".$row['channel']."&nbsp;</td>
<td>".$row['ip']."&nbsp;</td>
<td>".$row['totalcalls']."&nbsp;</td>";

if ($row['totalcalls']>1){

echo "<td>".$attenedcalls."&nbsp;</td>";
$disconnectedcalls=($row['totalcalls']-$attenedcalls);
echo "<td>".$disconnectedcalls."&nbsp;</td>";
echo " <td>".$row['tduration']."&nbsp;</td>";
echo "<td>".$asr."</td>";
}else{

echo "<td>".$row['totalcalls']."</td>";

echo "<td>100</td>";

}

$minutes = gmdate("H:i:s", ($row['tduration']/$attenedcalls));
echo " <td>".$minutes."&nbsp;</td>
</tr>";
}
?>
</table>

关于php - 如何给表 tr 上色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12276196/

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