-1

我们有以下用于报告代理数据库的 sql 代码..

<?php
$sql=mysql_query("SELECT Name, sum( Points )AS Total_Points
FROM`allagentper`
GROUP BY Name
ORDER BY Points DESC ");
print"<table >";
print"<tr><th>Name</th><th>Points</th></tr>";
while($row=mysql_fetch_assoc($sql))
{
print"<tr>";
foreach($row as $value)
{

print"<td>";
echo $value ;
print "</td>";
}

print"</tr>";

}

print"</table>";


mysql_close($con);



?>

结束报告显示为以下类型:

Name  points
abc     78
dks     65
sge     64
sdf     62    <= Blue
ssr     62    <= Blue
eew     60    <= Blue
asw     60    <= Blue

我需要为 sql 中的每 3 行着色行表。前 3 行将是红色的。第二个 3 行将是蓝色的。但条件是如果点相同,它应该只采用相同的颜色。如果你看到上面的报告示例,sdf、ssr、eew 是蓝色的。但 asw 也与 eew 相同,所以最后 4 行应该是蓝色。

4

1 回答 1

0

我会做这样的事情

<?php
$sql=mysql_query("SELECT name, sum( Points )AS total_points
FROM`allagentper`
GROUP BY Name
ORDER BY Points DESC ");
print"<table >";
print"<tr><th>Name</th><th>Points</th></tr>";
$rowCounter = 0;
$previousTotal = -9999999;
while($row=mysql_fetch_assoc($sql))
{

if($rowCounter % 6 > 3)
{
$color = "#FF0000";
}
else
{
$color = "#0000FF";
}

print"<tr>";
print"<td>".$row->name."</td>";
print"<td style='color:".$color."'>".$row->total_points."</td>";
print"</tr>";

if($row->total_points != $previousTotal)
{
rowCounter++;
}
$previousTotal = $row->total_points;
}

print"</table>";
mysql_close($con);
?>
于 2012-10-19T14:34:34.937 回答