我想改變整條線的顏色取決于日期的持續時間。例如,如果日期的持續時間在 3 到 6 之間,顏色為橙色;超過 6 個必須顯示為紅色。我可以知道我該怎么做嗎?
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 "  " .$v["seal_area"]. "     ";
echo "</font>\n";
echo "</td>\n";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
echo "  " .$v["seal_barcode"]. "     ";
echo "</font>\n";
echo "</td>\n";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
echo "  " .$v["dt_issue"]. "     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
echo "  " .$v["issue_admin"]. "     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
echo "  " .$v["receive_by"]."     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
echo "  " .$v["receive_id"]."     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
echo "  " .$v["dt_return"]."     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
echo "  " .$v["return_admin"]."     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
echo "  " .$v["return_by"]. "     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
echo "  " .$v["return_id"]."     ";
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 "  " .round($datediff / (60 * 60 * 24))."     ";
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 "  " .$daysDiff."     ";
echo "</font>\n";
echo "</td>";
echo "</tr>";
}
上面的代碼在 php 中,我如何計算回圈時間選項卡。對于 dt_issue,它在插入查詢時與 now() 一起使用。我將在下面插入螢屏截圖。

uj5u.com熱心網友回復:
你可以試試這個來改變字體的顏色取決于daysdiff
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 "  " .$daysDiff."     ";
echo "</font>\n";
echo "</td>";
如果你想改變整行的顏色,你應該在回顯<tr>標簽之前做,比如echo "<tr style=\"color:$color\">";
整行示例:
foreach ($ary_list as $k => $v) {
$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 "<tr style=\"color:$color\" bgcolor=\"#F5F5F5\">";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\n";
echo "  " .$v["seal_area"]. "     ";
echo "</font>\n";
echo "</td>\n";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\n";
echo "  " .$v["seal_barcode"]. "     ";
echo "</font>\n";
echo "</td>\n";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\n";
echo "  " .$v["dt_issue"]. "     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\n";
echo "  " .$v["issue_admin"]. "     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\n";
echo "  " .$v["receive_by"]."     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\n";
echo "  " .$v["receive_id"]."     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\n";
echo "  " .$v["dt_return"]."     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\n";
echo "  " .$v["return_admin"]."     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\n";
echo "  " .$v["return_by"]. "     ";
echo "</font>\n";
echo "</td>";
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\n";
echo "  " .$v["return_id"]."     ";
echo "</font>\n";
echo "</td>";
/*echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" >\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 "  " .round($datediff / (60 * 60 * 24))."     ";
echo "</font>\n";
echo "</td>";*/
echo "<td nowrap ".$rowspan.">\n";
echo "<font face=\"arial\" size=\"1\" color=\"$color\">\n";
echo "  " .$daysDiff."     ";
echo "</font>\n";
echo "</td>";
echo "</tr>";
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/478153.html
下一篇:如何在資料框中轉換日期格式
