jeudi 30 juin 2016

how can I change background color of dynamically filled table row based on the value of one of the cells?

I have a table being filled dynamically from mysql database. One of the columns in the table is a date. I want to change the background color of the row if the date is more than 3 days old. Trying to figure this out, I have figured out the formula and on a test.php page I can make it work with a textbox. I need to know how to apply it to a table row.

function call_log_date($enter_date)
{
    $today      = strtotime(date("m/d/Y"));
    $other_date = strtotime($enter_date) . "<br>";
    // returns number of days between dates(because of abs, will always
    // return positive number)
    $diff = ceil(abs($today - $other_date) / (60 * 60 * 24));
    if ($diff > 3) {
        $bg_color   = "#FFFF00"; //yellow
        $font_color = "#FF0000"; //red
    } else if ($diff > 1 && $diff <= 3) {
        $bg_color   = "#FFFFFF"; // white
        $font_color = "#FF0000"; //red
    } else {
        $bg_color   = "#FFFFFF"; // white
        $font_color = "#000000"; //black
    }

    return $bg_color . $font_color;
}

Above is the function that I am using that works for a textbox

Aucun commentaire:

Enregistrer un commentaire