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 "
CustomerID | Customer Name | Prospect Status | Address |
---|
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 YELLOWecho "
" . $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.