微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

基于MYSQL值突出显示PHP某种颜色的单元格

我有三个值可以显示mysql,RED,GREEN,YELLOW中的表/列中,用于字段“ProspectStatus”

反正我是否可以根据值改变背景颜色?

例如

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是3种颜色的值.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐