Ridgejp
asked on
Use MySQL & PHP to change a cell's background colour based upon results output.
Hi,
Looking for advice on how best to change the background colour of a cell's table row based upon it's contents.
This is the basic code: -
If the mySql Output for "<td> $row->totalAssemblyUnits </td>" is ever less than zero, then I like to colour the background of the cell red, otherwise it should be coloured green.
Hope that makes sense?
J
Looking for advice on how best to change the background colour of a cell's table row based upon it's contents.
This is the basic code: -
<div><h5>Process Check - Total No. of Units which Failed to Transfer (Last Addition)</h5></div>
<table id="table" class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th class="success text-left">Date of Deduction</th>
<th class="success text-left">Total No. of Units</th>
</tr>
</thead>
<tbody class="searchable">
<?php
$query = "select timestamp, totalAssemblyUnits from sumAssemblyUnitsGoodsIn2 order by timestamp desc limit 1";
if (!$result = $mysqli->query($query)) {
$err
= "QUERY FAIL: "
. $query
. ' ERRNO: '
. $mysqli->errno
. ' ERROR: '
. $mysqli->error
;
trigger_error($err, E_USER_ERROR);
}
while ($row = $result->fetch_object()) {
$tr = <<<EOD
<tr>
<td> $row->timestamp </td>
<td> $row->totalAssemblyUnits </td>
</tr>
EOD;
echo $tr;}
?>
</table>
If the mySql Output for "<td> $row->totalAssemblyUnits </td>" is ever less than zero, then I like to colour the background of the cell red, otherwise it should be coloured green.
Hope that makes sense?
J
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect thank you.
ASKER