conditional formatting html table in php with time stamp comparison -
echo '<table style="width:100%"> <tr>'; echo '<td>order</td>'; echo '<td>destination</td>'; echo '<td>location</td>'; echo '<td>status</td>'; echo '<td>timestamp</td>'; echo '</tr>'; if($result) { while($row = mysqli_fetch_assoc($result)) { echo '<tr><td>'; echo $row['ordernumber'] . ''; echo '</td><td>'; echo $row['destination'] . ''; echo '</td><td>'; echo $row['location'] . ''; echo '</td><td>'; echo $row['status'] . ''; echo '</td><td>'; echo $row['timestamp'] . ''; echo '</td></tr>'; } echo '</table>';
}
i want change background of row turned different color time stamp more 60 minutes past current time. appreciated. dont know begin.
thanks
edit: format of time stamp "2015-07-17 19:17:31"
do if see if time on 60 minutes , if assign class different background color. since didn't clarify i'm going assume using unix timestamp time()
.
$currtime = time(); if($result) { while($row = mysqli_fetch_assoc($result)) { $calc = $currtime - $row['timestamp']; if($calc > 3600){ $rowclass = "oldorder"; } else { $rowclass = "normalorder"; } echo '<tr class="'.$rowclass.'"><td>'; echo $row['ordernumber'] . ''; echo '</td><td>'; echo $row['destination'] . ''; echo '</td><td>'; echo $row['location'] . ''; echo '</td><td>'; echo $row['status'] . ''; echo '</td><td>'; echo $row['timestamp'] . ''; echo '</td></tr>'; }
then add css define 2 classes
.oldorder{ background-color: #ccc; } .normalorder{ background-color: #fff; }
Comments
Post a Comment