Rumah  >  Soal Jawab  >  teks badan

Tukar warna bergantung pada nilai tarikh

Saya ingin menukar warna keseluruhan baris berdasarkan tempoh tarikh. Contohnya, jika tempoh tarikh adalah antara 3 dan 6, warna oren lebih daripada 6 mesti dipaparkan dalam warna merah. Bolehkah saya tahu bagaimana saya boleh melakukan ini?

foreach ($ary_list as $k => $v) {

 $color= xxx;
 echo "<tr style=\"color:$color\">";
 echo  "<tr bgcolor=\"#F5F5F5\">\n";
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["seal_area"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>\n";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["seal_barcode"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>\n";
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["dt_issue"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";  
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["issue_admin"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["receive_by"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["receive_id"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
 
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["dt_return"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["return_admin"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["return_by"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["return_id"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
  
  /*echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  $now = time(); // or your date as well
    $your_date = strtotime($v["dt_issue"]);
    $datediff = $now - $your_date;

//echo round($datediff / (60 * 60 * 24));
    //echo $datediff->format('%R%a days');
  echo  "&nbsp " .round($datediff / (60 * 60 * 24))." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";*/
  
  echo "<td nowrap ".$rowspan.">\n";
    $now = time();
    $your_date = strtotime($v["dt_issue"]);
    $datediff = $now - $your_date;
    $daysDiff = round($datediff / (60 * 60 * 24));
    $color = $daysDiff < 3 ? '#3C5F84' : ($daysDiff <= 6 ? 'orange' : 'red');
    echo  "<font face=\"arial\" size=\"1\" color=\"$color\">\n";
    echo  "&nbsp " .$daysDiff." &nbsp &nbsp ";
    echo  "</font>\n";
    echo  "</td>";

  echo  "</tr>";
  
}

Kod di atas ialah cara saya mengira tab masa kitaran dalam php. Untuk dt_issue, ini digunakan dengan now() apabila memasukkan pertanyaan. Saya akan memasukkan tangkapan skrin di bawah.

P粉459440991P粉459440991222 hari yang lalu477

membalas semua(1)saya akan balas

  • P粉947296325

    P粉9472963252024-04-04 00:54:42

    Anda boleh cuba menukar warna fon berdasarkan daysdiff

    echo "\n";
    $now = time();
    $your_date = strtotime($v["dt_issue"]);
    $datediff = $now - $your_date;
    $daysDiff = round($datediff / (60 * 60 * 24));
    $color = $daysDiff < 3 ? '#3C5F84' : ($daysDiff <= 6 ? 'orange' : 'red');
    echo  "\n";
    echo  "  " .$daysDiff."     ";
    echo  "\n";
    echo  "";

    balas
    0
  • Batalbalas