I have a form where you can type in a given time for example 12:30.
Default the table color is blue but i want it to change color if the current real time is 12:30 or above (example: 12:40).
I need to fetch the given time from the database (already managed that) but the next part is to get the current time and if its equal or higher than the input time change color of the whole table
(Inntid is the value where you type in your own time)
HTML:
<table>
<tr>
<th>Båt ut</th>
<th>Båt inn</th>
<th>Båtnr</th>
<th>Fornavn</th>
<th>Etternavn</th>
<th>Tid</th>
<th>Kr</th>
</tr>
CSS:
table {
color: blue;
outline-style: solid;
width: 100%;
font-family: monospace;
font-size: 25px;
text-align:left;
}
th {
color: red;
font-family: monospace;
font-size: 25px;
text-align:left;
}
PHP:
$sok = @$_POST['searchh'];
$sql = "SELECT utleid, inntid, baatnr, fornavn, etternavn, tid, kr FROM utleie WHERE baatinn = '0' ORDER BY id desc";
$result = $conn-> query($sql);
if ($result-> num_rows > 0) {
while ($row = $result-> fetch_assoc()) {
echo "<tr><td>".
$row["utleid"] ."</td><td>".
$row["inntid"] ."</td><td>".
$row["baatnr"] ."</td><td>".
$row["fornavn"] ."</td><td>".
$row["etternavn"] ."</td><td>".
$row["tid"] ."</td><td>".
$row["kr"] ."</td></tr>";
}
echo "</table>";
}
else {
echo "0 results";
}
echo $row;
$conn-> close();
?>
</table>
Define your CSS class to be whatever you'd like it to be if the condition is true, then check if the time of $row['tid']
is equal or higher to the current date - if true, add that class to your td
element.
CSS would be something like
.future_time {
background-color: red;
}
And your PHP would be something like this,
<?php
$sok = @$_POST['searchh'];
$sql = "SELECT utleid, inntid, baatnr, fornavn, etternavn, tid, kr FROM utleie WHERE baatinn = '0' ORDER BY id desc";
$result = $conn-> query($sql);
if ($result-> num_rows > 0) {
echo '<table>';
$now = new DateTime();
while ($row = $result-> fetch_assoc()) {
$tid = new DateTime($row["tid"]);
$tid_class = $tid >= $now ? 'future_time' : '';
?>
<tr>
<td><?php echo $row["utleid"]; ?></td>
<td><?php echo $row["inntid"]; ?></td>
<td><?php echo $row["baatnr"]; ?></td>
<td><?php echo $row["fornavn"]; ?></td>
<td><?php echo $row["etternavn"]; ?></td>
<td class="<?php echo $tid_class; ?>"><?php echo $tid ?></td>
<td><?php echo $row["kr"]; ?></td>
</tr>
<?php
}
echo "</table>";
} else {
echo "0 results";
}
$conn-> close();