Page 1 of 1
How to color a particular column in a table using PHP
Posted: Wed Oct 05, 2005 2:36 pm
by chipotle
I have a table displayed that is retreived from the database. Based on a value in a particular column I need to change the color of that display. eg. column status can hold the values new, approved, rejected etc.. I want to color that column based on the values. If it is new then green, approved then blue etc...
Please help

Posted: Wed Oct 05, 2005 3:02 pm
by feyd
look at the value in the current record, emit either a color via a div/span or set the table cell to a particular class.. a basic (untested) example
Code: Select all
// assume $row is an associative array of the record's details
switch(strtolower($row['status'])) {
case 'new':
$cell = 'green';
break;
case 'approved':
$cell = 'blue';
break;
case 'rejected':
$cell = 'red';
break;
}
echo '<td class="'.$cell.'">'.$row['status'].'</td>';
// emit the rest of the record's junk