使用php更改td颜色if else语句[关闭]

I want to change color of my td as per the date received from the sql query. Please help with following -

I want to change the color of td to green if the fetched date is less than today's date.

<?php
    if($mydate > date('d-M-Y'))
    {
        echo "<td style="background-color:green;">";
    }
    else
    {
       echo "<td>";
    }
?>
$mydate = "2015-10-01";
if(strtotime($mydate) > strtotime(date('Y-m-d')))
{
    echo "<td style='background-color:green;'>testing</td>";
}
else
{
   echo "<td>testing</td>";
}

You cannot check dates in string formats.

One way you could do that is by formatting dates in UNIX timestamp (so that you have an integer) allowing you to check properly if a date is actually newer or older than another one.

$mydate = (new DateTime($mydate))->format('U');
$date   = (new DateTime(date('Y-m-d')))->format('U');

if($mydate > $date)
{
    echo "<td style='background-color: green;'>";
}
else
{
    echo "<td>";
}

First convert your both time to a single format and compare

try following

I have used div instead of td for easy of use

<?php
    $mydate="08-sep-2015";
    //$mydate="11-sep-2015";
    $today      = date('d-M-Y');
    $todayTime = strtotime($today);
    $compTime  = strtotime($mydate);
    if($compTime < $todayTime) {        
        echo "<div style='background-color:green;'>fgd</div>";
        }
        else{
                echo "<div>sdfsdf</div>";
         }
?>
    <!DOCTYPE html>
     <html>
   <head>

   </head>
   <body>

   <table>

   <tr>

    <?php
    $mydate = "2015-10-01";
    if(strtotime($mydate) > strtotime(date('Y-m-d')))
    {
        echo "<td  bgcolor='#FF0000'>testing</td>";
    }
    else
    {
       echo "<td>NOt Green</td>";
    }
    ?>

    </tr>
    </table>



    </body>
    </html>