0

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

<?php
//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 ..

echo'<tr>

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


}


//close the table so HTML wont suffer :P
echo'</table>'; 
?>

I change this :

If ($part[2] == 'error') 
{
echo '<td width="400" bgcolor="red">'.$part[2].'</td>';
}
else
{
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?

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by simplypixie
0

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

A quick example of this:

.lol:nth-child(even){
    background-color:#FFF;
}
.lol:nth-child(odd){
    background-color:#000;
}
1

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):

echo'<tr';

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

echo '>';
Votes + Comments
css is the way to go
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.