I need some help tweaking this php code to print out a default value for a specific column.
I'm printing out the following column header columns in a table: Host Target Date Set Time Length Size Status
There are instances in the 'tst.txt' input file where I don't have data for the last (3) columns Length Size Status
I originally was creating a blank cells for this data, but now I want to put a DEFAULT data for only the column: Status
where if status is null then print CHECK FOR ERRORS
as an example.
I tried coding that below, but its doing it for every blank cell, but I just want it for column status. Thanks!
<?php
$data = array();
$InputFile = file("tst.txt");
foreach ($InputFile as $line){
preg_match_all("/([0-9])-([^=]+)=([^;]+);/", $line, $matches, PREG_SET_ORDER);
$LineData = array();
foreach ($matches as $information)
{
$LineData[$information[2]] = $information[3];
}
$timestamp = strtotime($LineData["Date"]." ".$LineData["Time"]);
$data[$timestamp] = $LineData;
}
ksort($data);
$keys = array('Host', 'Target','Date','Set','Time', 'Length','Size','Status');
echo '<table><tr>';
foreach ($keys as $column)
echo '<th>' . $column . '</th>';
echo '</tr>';
foreach ($data as $row){
echo '<tr>';
foreach ($keys as $column)
if (isset($row[$column])){
echo '<td>' . $row[$column];
} else {
//echo '<td>' . '' . '</td>';
echo '<td>' . 'Check for Errors' . '</td>';
}
}
echo '</table>';
//print_r($data);
?>
foreach ($data as $row){
echo '<tr>';
foreach ($keys as $column)
if (isset($row[$column])){
echo '<td>' . $row[$column] . '</td>';
} elseif ($column == 'Status') {
echo '<td> Check for Errors </td>';
} else {
echo '<td> </td>';
}
}
is probably about what you're looking for.