根据MYSQL值突出显示PHP单元格某种颜色 [英] Highlighting a cell PHP a certain color based on MYSQL value
本文介绍了根据MYSQL值突出显示PHP单元格某种颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个值可以从mysql中的表/列中显示,字段"ProspectStatus"的红色,绿色和黄色
I have three values that can be displayed from a table/column in mysql, RED, GREEN, YELLOW for the field "ProspectStatus"
无论如何,我可以使单元格根据值更改其背景颜色吗?
Is there anyway I can make a cell change its background color based on the value?
例如
echo "<td>" . $row['ProspectStatus'] . "</td>";
PHP代码:
$result = mysql_query("SELECT * FROM customerdetails");
//List the Columns for the Report
echo "<table border='1'>
<tr>
<th>CustomerID</th>
<th>Customer Name</th>
<th>Prospect Status</th>
<th>Address</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['CustomerID'] . "</td>";
echo "<td>" . $row['CustomerName'] . "</td>";
echo "<td>" . $row['ProspectStatus'] . "</td>"; //this is the field I want to show either RED, GREEN or YELLOW
echo "<td>" . $row['Address'] . "</td>";
echo "</tr>";
}
echo "</table>";
推荐答案
您可以这样做:
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['CustomerID'] . "</td>";
echo "<td>" . $row['CustomerName'] . "</td>";
if($row['ProspectStatus']=='[val1]') // [val1] can be 'approved'
echo "<td style='background-color: #00FF00;'>".$row['ProspectStatus']."</td>";
else if($row['ProspectStatus']=='[val2]')// [val2]can be 'rejected'
echo "<td style='background-color: #FF0000;'>".$row['ProspectStatus']."</td>";
else if($row['ProspectStatus']=='[val3]') //[val3] can be 'on hold'
echo "<td style='background-color: #FFFF00;'>".$row['ProspectStatus']."</td>";
echo "<td>" . $row['Address'] . "</td>";
echo "</tr>";
}
echo "</table>";
状态的值可能取决于颜色.我假设val1
,val2
和val3
是这三种颜色的值.
The value of the status may depend on the color. I assume that val1
, val2
and val3
are the values of the 3 colors.
这篇关于根据MYSQL值突出显示PHP单元格某种颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文