swamp Posted April 24, 2008 Share Posted April 24, 2008 Hi there, I've got a php script that reads from a txt file database.. <?php echo ' <table cellpadding="3"> '; $fp = fopen('dep.txt','r'); if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;} while (!feof($fp)) { $line = fgets($fp,1024); //use 2048 if very long lines $row++; list ($code, $project, $destination, $gate, $time, $remarks) = split ('\|', $line); $col[$row] = array($code, $project, $destination, $gate, $date, $remarks); } fclose($fp); sort($col); reset ($col); $arrays = count($col) - 1; $loop = -1; while ($loop < $arrays) { $loop++; echo ' <tr> <td width="242" align="left" bgcolor="#161616" class="style5">'.$col[$loop][1].'</td> <td width="14" class="style5"> </td> <td width="180" align="left" bgcolor="#161616" class="style5">'.$col[$loop][2].'</td> <td width="14" class="style5"> </td> <td width="80" bgcolor="#161616" class="style5"><div align="center">'.$col[$loop][3].'</div></td> <td width="14" class="style5"> </td> <td width="80" bgcolor="#161616" class="style5"><div align="center">'.$col[$loop][4].'</div></td> <td width="13" class="style5"> </td> <td width="106" bgcolor="#161616" class="style5"><div align="center">'.$col[$loop][5].'</div></td> </tr>'; } echo ' </table> '?> I need the $date to be checked on how soon it is to the current date, and for it to go red when it is two days away. This only needs to work in IE as its just used for internal stuff, not publicly for the web. Any help would be appreciated! Thank you! Link to comment https://forums.phpfreaks.com/topic/102684-changing-text-colour-if/ Share on other sites More sharing options...
kenrbnsn Posted April 24, 2008 Share Posted April 24, 2008 Change your loop to be: (this assumes that the date, stored in $col[$loop][4], is in some sort of standard format) <?php $tda = strtotime('-2 days'); for ($loop = 0;$loop < $arrays;$loop++) { $dc = (strtotime($col[$loop][4]) <= $tda)?'<span style="color:red">':'<span>'; echo ' <tr> <td width="242" align="left" bgcolor="#161616" class="style5">'.$col[$loop][1].'</td> <td width="14" class="style5"> </td> <td width="180" align="left" bgcolor="#161616" class="style5">'.$col[$loop][2].'</td> <td width="14" class="style5"> </td> <td width="80" bgcolor="#161616" class="style5"><div align="center">'.$col[$loop][3].'</div></td> <td width="14" class="style5"> </td> <td width="80" bgcolor="#161616" class="style5"><div align="center">'.$dc.$col[$loop][4].'</span></div></td> <td width="13" class="style5"> </td> <td width="106" bgcolor="#161616" class="style5"><div align="center">'.$col[$loop][5].'</div></td> </tr>'; }?> Untested. Ken Link to comment https://forums.phpfreaks.com/topic/102684-changing-text-colour-if/#findComment-525883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.