如何根据值将单元格变为红色和绿色?我希望单元格值改变颜色,如上图所示。
$data = array();
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();
$nestedData[] = $row["no"];
$nestedData[] = $row["svcno"];
$nestedData[] = $row["pangkat"];
$nestedData[] = $row["name"];
$nestedData[] = $row["year"];
$nestedData[] = $row["system"];
$nestedData[] = $row["course"];
$nestedData[] = $row["f1"];
$nestedData[] = $row["f2"];
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every
request/draw by clientside , they send a number as a parameter, when they
recieve a response/data they first check the draw number, so we are sending
same number in draw.
"recordsTotal" => intval( $totalData ), // total number of
records
"recordsFiltered" => intval( $totalFiltered ), // total number of
records after searching, if there is no searching then totalFiltered =
totalData
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
?>
答案 0 :(得分:0)
以下示例说明如何通过动态更改表中td标记的背景颜色属性来更改所需值的颜色。您应该能够研究这一点并使其适应您的代码。
$array = array(1,4,3,7,8,3,5,7,1,8,1,5,6);
echo
'<table>' .
'<tr>' .
'<th>Value</th>' .
'</tr>';
foreach($array as $key){
if($key <= 3){
$color = 'green';
}elseif($key > 3 && $key <= 6){
$color = 'yellow';
}elseif($key > 6 && $key <= 10){
$color = 'red';
}
echo
'<tr>' .
'<td style="background-color:' . $color . ';">' . $key . '</td>' .
'</tr>';
}
echo
'</table>';