0

How can I change the different color of date if the date in the database is greater than today's date. In Picture, U can see the date under 002 is greater than today's date so the color must be green. If less tha toda's date, it has to be red. How can I do auto detect the date?

$type = $equipArray[$x];
$sql = "SELECT * FROM map_db_oee.`tbl_actual_correlation` WHERE `waferid` LIKE 'NSX1234%' AND prober=' '".$type."' ORDER BY dt_cor DESC LIMIT 1'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
  $row = mysqli_fetch_array($result);
  $date = "<br><font size=\"2px\" color=\"red\">".$row["dt_corr"]." </font>";
}
else {
  $date = "";
}

Date must be green and auto detected.

This is example of code

kiner_shah
  • 3,939
  • 7
  • 23
  • 37

1 Answers1

0
<?php $class = strtotime($row['dt_cor']) < time()  ? 'past' : 'up-coming'; ?>

<style>
    .date-el{font-size: 14px;display: inline-block;color: #000;}
    .date-el.past{color: #ccc;}
    .date-el.up-coming{color: #f00;}
</style>

<span class="date-el <?= $class; ?>"><?= $row['dt_cor']; ?></span>

adding style / class can solve your problem

add the css inside <head> tag, or it will be better if you maintain it inside your css file. check css tutorial

D Coder
  • 331
  • 2
  • 10
  • Where should i put that style? –  Nov 19 '21 at 04:16
  • Where should i add the span class? –  Nov 19 '21 at 05:58
  • you can keep the date inside the span-element. But add the css classes ( as mentioned there ). date here . The css/class is used to change the style of the html output. – D Coder Nov 19 '21 at 06:09