使用 php 更改记录集 return 的颜色

change color on recordset return using php

我在 MySQL table 中为状态列使用了有限的、已知数量的状态,并且希望在其中有一个易于识别的警报来反映特定状态。

如何根据 'status' 列的内容更改 php 生成的 HTML table 中单元格的背景颜色?

例如'complete' = 绿色,“待处理”= 橙色

这是 table 的条目:

<td><?php echo $row_Recordset1['status']; ?> </td>

我可以在上面添加什么 php 代码来完成条件颜色更改?

谢谢。

我不确定你想要什么... 但是:

当您拥有状态数组时,只需执行一个 foreach,例如:

foreach($array as $key => $value) {

  if($value['field'] == "car") {
   $color = red;
  }
  elseif($value['field'] == "bike") {
   $color = blue;
  }

}

也许这种方式可以帮助....

CSS

.complete { background: green; }
.pending { background: orange; }

php

$status_class ="";
if($row_Recordset1['status'] == "complete"){
   $status_class = "complete";
}else if($row_Recordset1['status'] == "pending"){
   $status_class = "pending";   
}

HTML

<td class='<?=$status_class;?>'><?php echo $row_Recordset1['status']; ?> </td>