突出显示表html中的一行,其值超过平均值

时间:2017-07-11 07:49:35

标签: mysql

我有一张看起来像这样的桌子。 MyTable

我想要做的是,我想突出显示(黄色颜色)哪一行的使用率比AVERAGE高1K。结果应如下所示。 enter image description here

以下是我的代码,当超过平均值时,将行设置为高亮,但我无法将值if($row['duh']>'0.77')更改为if($row['duh']>'$avg'),因为它会高亮显示所有行。

$no   = 1;
while ($row = mysqli_fetch_array($result))
{
  $month1=strtotime($row['month']);
  $month=date('m-Y',$month1);
  $store_name=$row['store_name'];
  $netamt1=$row['netamt'];
  $netamt11=number_format($netamt1,2);
  $usage1=$row['monusage'];
  $usage11=number_format($usage1,2);
  $answer=$usage1/$netamt1*1000;
  $answer1=number_format($answer,2);
  $total+=$answer1;
  $avg=$total/$no;
  $duh = number_format($row['duh'],2);

   echo "<tr>"; 
   echo "<td>".$no."</td>"; 
   echo "<td>".$store_name."</td>"; 
   echo "<td>".$date2111."</td>";
   echo "<td>".$netamt11."</td>"; 
   echo "<td>".$usage11."</td>";  
   if($row['duh']>'0.77') {// 0.77 i cannot change to $avg, because it will hightlight all the rows become yellow
   echo "<td style='background-color: #FFFF00;'>".$duh."</td>";}
   else {
       echo "<td>".$duh."</td>";
    } 
   echo "</tr>"; 
  $no++;
}?>
</tbody>
<tfoot>
  <tr>
    <th colspan="5">TOTAL</th>
    <th><?=($total)?></th>
  </tr>
  <tr>
  <th colspan="5">AVERAGE</th>
  <th><?=number_format($avg,4)?></th>
  </tr>
</tfoot>

2 个答案:

答案 0 :(得分:1)

您可以在查询结果中添加Button does not contain DayOfWeek property作为另一列,并将值与其进行比较,例如:

avegage

然后,添加以下内容以突出显示:

SELECT no, outlet, date, sales, usage, usage_per_1k, AVG(usage_per_1k) AS avg
FROM table
WHERE condition;

答案 1 :(得分:0)

继续尝试之后,现在我想出如何根据平均条件高亮一行,如果高于平均值,该行将为黄色,但我现在将其变为红色。如果低于平均值,颜色将不会改变。我在shaded.a.b.c.d中使用脚本,然后添加<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> <configuration> <shadedArtifactAttached>false</shadedArtifactAttached> <outputDirectory>${project.build.directory}</outputDirectory> <createDependencyReducedPom>true</createDependencyReducedPom> <promoteTransitiveDependencies>true</promoteTransitiveDependencies> <shadeSourcesContent>true</shadeSourcesContent> <relocations> <relocation> <pattern>a.b.c</pattern> <shadedPattern>shaded.a.b.c</shadedPattern> </relocation> </relocations> </configuration> </plugin> ,然后执行功能。

<body> tag

结果如下: Result