I have code , and I need to change color row when in last column 'status' appears value = 'error'

//first, get the file...
$file = file('log.txt');

//now count the lines ..
$lines = count($file);

//start the table here..
echo '</br>';
echo'<table border="1" width="600">';
echo '    <td width="400">Date</td>';
echo '    <td width="300">Name</td>';
echo '    <td width="400">Status</td>';

//start the loop to get all lines in the table..
for ($i=0; $i<=$lines; $i++) {

//get each line and exlplode it..
  $part = explode(';', $file[$i]);
//now start printing ..


              <td width="400">'.$part[0].'</td>
              <td width="300">'.$part[1].'</td>
              <td width="400">'.$part[2].'</td>


//close the table so HTML wont suffer :P

I change this :

If ($part[2] == 'error') 
echo '<td width="400" bgcolor="red">'.$part[2].'</td>';
echo '<td width="400" bgcolor="green">'.$part[2].'</td>;

but this did not work - no color change in row
someone has an idea how to improve?

If you don't mind being non-compatible with older browsers you could use css3's nth-child.

A quick example of this:


Use CSS to set a background colour to rows with errors:

tr.error {
  backround-color: red;

Then check if there is an error and if so, apply the style to your table row (replaces line 22 in your posted code):


if ($part[2] == 'error') { echo ' class="error"'; }

echo '>';
commented: css is the way to go +14