当日期比昨天早时,我如何突出显示一行


how can i highlight a row when date is older than yesterday

我对jQuery和JavaScript非常陌生。我有一个小问题。假设我有一个HTML表,如下面的

<?php 
    include 'dbconnect.php'; 
    $sql = "SELECT * FROM Comments";            
    $result = mysqli_query($conn,$sql); 
    if (!$result) { 
        echo '<div>no comments were set up</div>'; 
    } 
    $fields_num = mysqli_num_fields($result);
    echo "<h1>Table: {$table}</h1>";
    echo "<table id='myTable' border='1'><tr>";
    // printing table headers
    for($i=0; $i<$fields_num; $i++)
    {
        $field = mysqli_fetch_field($result);                       
        echo "<td>{$field->name}</td>";                     
    }
    echo "</tr>'n";
    // printing table rows
    while($row = mysqli_fetch_row($result))
    {
        echo "<tr>";
        // $row is array... foreach( .. ) puts every element
        // of $row to $cell variable
        foreach($row as $cell)
        echo "<td>$cell</td>";
        //delete button
        echo "<td><input type='button' value='Delete' onclick='deleteRow(this)'></td>";
        //checkbox button
        echo "<td><input type='checkbox' value='Highlight' onclick='highlight(this)'></td>";
        echo "</tr>'n";
    }
    mysqli_free_result($result);             
?>

我想检查第8列中的日期是否早于该行应该突出显示的日期。我该怎么办。

我找到了一个代码,但它不起作用:

           function checkdate(){
           $('#myTable  tr td').each(function () {
           var dtTd = new Date($(this).html());
           var dtNew = new Date();
          // 15 minutes is 900000 milliseconds
        // getTime() doc - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime
           if (dtTd.getTime() - dtNew.getTime() < 900000 && dtNew < dtTd) {
            $(this).css("background-color", "red");
            } else {
             if (dtNew > dtTd) {
          $(this).css("background-color", "yellow");
            }
            }
            });
             }

试试这个:

$date = date('Y-m-d');
foreach($row as $cell)
{
    if($cell['date'] < $date)
    {
        // for date less then today's date
    }
    else
    {
        // for others date
    }
}