Ich möchte die Farbe der gesamten Zeile basierend auf der Dauer des Datums ändern. Wenn die Dauer des Datums beispielsweise zwischen 3 und 6 liegt, muss die Farbe Orange sein; mehr als 6 muss in Rot angezeigt werden. Darf ich wissen, wie ich das machen kann?
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>"; }
Mit dem obigen Code berechne ich die Registerkarte „Zykluszeit“ in PHP. Für dt_issue wird dies beim Einfügen der Abfrage mit now() verwendet. Ich füge unten einen Screenshot ein.
您可以尝试根据daysdiff更改字体颜色