php mysql 高亮显示,根据MYSQL值突出显示PHP单元格某种颜色

这篇博客讨论了如何在PHP中根据MySQL查询结果改变表格单元格的背景颜色。通过检查'ProspectStatus'字段的值(RED, GREEN, YELLOW),可以使用条件语句为每个单元格设置不同的颜色。例如,当状态为RED时,单元格显示为红色背景,GREEN为绿色,YELLOW为黄色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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?

e.g.

echo "

" . $row['ProspectStatus'] . "";

PHP Code:

$result = mysql_query("SELECT * FROM customerdetails");

//List the Columns for the Report

echo "

CustomerIDCustomer NameProspect StatusAddress

while($row = mysql_fetch_array($result))

{

echo "

";

echo "

" . $row['CustomerID'] . "";

echo "

" . $row['CustomerName'] . "";

echo "

" . $row['ProspectStatus'] . ""; //this is the field I want to show either RED, GREEN or YELLOW

echo "

" . $row['Address'] . "";

echo "

";

}

echo "

";

解决方案

You can do this with this:

while($row = mysql_fetch_array($result))

{

echo "

";

echo "

" . $row['CustomerID'] . "";

echo "

" . $row['CustomerName'] . "";

if($row['ProspectStatus']=='[val1]') // [val1] can be 'approved'

echo "

".$row['ProspectStatus']."";

else if($row['ProspectStatus']=='[val2]')// [val2]can be 'rejected'

echo "

".$row['ProspectStatus']."";

else if($row['ProspectStatus']=='[val3]') //[val3] can be 'on hold'

echo "

".$row['ProspectStatus']."";

echo "

" . $row['Address'] . "";

echo "

";

}

echo "";

The value of the status may depend on the color. I assume that val1, val2 and val3 are the values of the 3 colors.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值