I have a page using php/html which displays a dashboard of 8 tables built using 5 MYSQL result sets. I am wanting to change the background color of various columns based on the value contained in the columns cell. I have seen a few threads of a similar topic which have got me this far, but none of them could talk me through my specific issues, so I'm hoping someone can enlighten me. :)
Issue 1. The code below works sorta, but it is using only the first result value to define the entire columns cell color, and not individually defining each row in the column.
Issue 2. even if it was working for one result set I'm not sure how to implement it to work with all my other required result sets on the page without copying and pasting the code snippet 8 times with each different result row assigned to = $cellcolor.
In case it is relevant the rows i would like affected are...
- $row_recordset1['check1']
- $row_recordset1['check2']
- $row_recordset1['check3']
- $row_recordset2['rating']
- $row_recordset3['check1']
- $row_recordset3['check2']
- $row_recordset3['check3']
- $row_recordset4['rating']
php Snippet...
<?php
$cellcolor=$row_recordset2['rating'];
if (($cellcolor <= 100) && ($cellcolor > 85))
$color = "#C98910";
else if (($cellcolor <= 85) && ($cellcolor > 70))
$color = "#A8A8A8";
else if (($cellcolor <= 70) && ($cellcolor > 65))
$color = "#965A38";
else if ($cellcolor <= 65)
$color = "#000000";
?>
Usage snippet...
<table border="1">
<tr><td class="table_data">rating</td></tr>
<?php do { ?>
<tr class="profile" align="center">
<td class="rating" bgcolor=<?php echo $color; ?>><a href="rating.php?TargetEvent=<?php echo $row_recordset2['code1']; ?>"><?php echo $row_recordset2['rating']; ?>
</tr>
<?php } while ($row_recordset2 = mysql_fetch_assoc($recordset2)); ?>
</table>